Skip to content

Instantly share code, notes, and snippets.

@preetpalS
Last active November 7, 2016 00:04
Show Gist options
  • Save preetpalS/2bf5c0d45c0e4de04629 to your computer and use it in GitHub Desktop.
Save preetpalS/2bf5c0d45c0e4de04629 to your computer and use it in GitHub Desktop.
Windows 10 UWP quick-and-dirty scaled image asset generation with ImageMagick
## Instructions
# 1. Place this file (modified appropriately with your paths) in folder with images to be scaled.
# 2. Run this file with Ruby (e.g. "ruby scale_win10_uwp_assets.rb").
## Results
# Creates a folder named "compiled_images" with scaled images.
## Notes
# You should create appropriate versions of your assets for different uses (and their scales and/or targets).
## Code
convert_executable = 'C:\Users\am\Downloads\ImageMagick-6.9.3-0-portable-Q16-x64\convert.exe' # use 'convert' if ImageMagick is in path
# Replace with names of your files
square_image_filename = 'SquareImage.png' # Should be at least 1200x1200 to avoid being enlarged
square_image_plated_filename = 'SquareImagePlated.png' # Should be at least 256x256 to avoid being enlarged
square_image_unplated_filename = 'SquareImageUnplated.png' # Should be at least 256x256 to avoid being enlarged
rectangular_image_filename = 'RectangularImage.png' # Should be at least 2480x1200 to avoid being enlarged
# Had separate images for 24x24 and 16x16 assets
square_image_plated24_filename = 'SquareImagePlated24AndBelow.png' # Should be at least 24x24 to avoid being enlarged
square_image_unplated24_filename = 'SquareImageUnplated24AndBelow.png' # Should be at least 24x24 to avoid being enlarged
square_image_sizes = [
# Square 71x71 logo
284, # Scale 400
142, # Scale 200
71, # Scale 100
107, # Scale 150
89, # Scale 125
# Square 150x150 logo
600, # Scale 400
300, # Scale 200
150, # Scale 100
225, # Scale 150
188, # Scale 125
# Square 310x310 logo
1240, # Scale 400
620, # Scale 200
310, # Scale 100
465, # Scale 150
388, # Scale 125
# Square 44x44 logo
176, # Scale 400
88, # Scale 200
44, # Scale 100
66, # Scale 150
55, # Scale 125
# Store logo:
200, # Scale 400
100, # Scale 200
75, # Scale 150
63, # Scale 125
50, # Scale 100
# Badge logo
96, # Scale 400
48, # Scale 200
36, # Scale 150
30, # Scale 125
# 24 # Scale 100
]
square_image_plated_sizes = [
# Square 44x44 logo
256, # Target size 256
48 # Target size 48
# 24, # Target size 24
# 16 # Target size 16
]
square_image_unplated_sizes = [
# Square 44x44 logo
256, # Unplated Target size 256
48 # Unplated Target size 48
# 24, # Unplated Target size 24
# 16 # Unplated Target size 16
]
rectangular_image_sizes = [
# Wide 310x150 logo
[1240, 600], # Scale 400
[620, 300], # Scale 200
[310, 150], # Scale 100
[465, 225], # Scale 150
[388, 188], # Scale 125
# Wide 310x150 logo
[2480, 1200], # Scale 400
[1240, 600], # Scale 200
[930, 450], # Scale 150
[775, 375], # Scale 125
[620, 300] # Scale 100
]
system('mkdir compiled_images')
square_image_sizes.each do |pixel_width|
system("#{convert_executable} #{square_image_filename} -resize x#{pixel_width} compiled_images/#{square_image_filename.gsub(/.png$/, '')}_#{pixel_width}x#{pixel_width}.png")
end
square_image_plated_sizes.each do |pixel_width|
system("#{convert_executable} #{square_image_plated_filename} -resize x#{pixel_width} compiled_images/#{square_image_plated_filename.gsub(/.png$/, '')}_#{pixel_width}x#{pixel_width}.png")
end
square_image_unplated_sizes.each do |pixel_width|
system("#{convert_executable} #{square_image_unplated_filename} -resize x#{pixel_width} compiled_images/#{square_image_unplated_filename.gsub(/.png$/, '')}_#{pixel_width}x#{pixel_width}.png")
end
rectangular_image_sizes.each do |pixel_width, pixel_height|
system("#{convert_executable} #{rectangular_image_filename} -resize #{pixel_width}x#{pixel_height}! compiled_images/#{rectangular_image_filename.gsub(/.png$/, '')}_#{pixel_width}x#{pixel_height}.png")
end
# Special code for sizes 24 pixels and below #
[24, 16].each do |pixel_width|
system("#{convert_executable} #{square_image_plated24_filename} -resize x#{pixel_width} compiled_images/#{square_image_plated_filename.gsub(/.png$/, '')}_#{pixel_width}x#{pixel_width}.png")
end
[24, 16].each do |pixel_width|
system("#{convert_executable} #{square_image_unplated24_filename} -resize x#{pixel_width} compiled_images/#{square_image_unplated_filename.gsub(/.png$/, '')}_#{pixel_width}x#{pixel_width}.png")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment