Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rynbyjn/6a6cf578997ff81f2d8a to your computer and use it in GitHub Desktop.
Save rynbyjn/6a6cf578997ff81f2d8a to your computer and use it in GitHub Desktop.
Generate Apple app icon sizes from a larger image

Generate Apple App Icon sizes from a larger image

ruby generate_app_icon_sizes.rb path_to_large_image

#!/usr/bin/env ruby
require 'bundler/setup'
require 'mini_magick'
class GenerateAppIconSizes
def initialize(file_path, base_file_name)
return puts 'You need an app icon file path to start from' unless file_path.length > 0
`mkdir tmp`
@file_path = file_path
@base_file_name = base_file_name || 'AppIcon'
process_size(29, 29)
process_size(40, 40)
process_size(60, 60, true, false)
process_size(76, 76, false)
end
def process_size(width, height, include_3x=true, include_1x=true)
file_name = "#{@base_file_name}#{width}x#{height}"
puts "generating #{file_name}"
img = MiniMagick::Image.open(@file_path)
img.format 'png'
if include_3x
# make @3x version first
img.resize "#{width*3}x#{height*3}"
img.write "tmp/#{file_name}@3x.png"
end
# make @2x version second
img.resize "#{width*2}x#{height*2}"
img.write "tmp/#{file_name}@2x.png"
# make reg version last
if include_1x
img.resize "#{width}x#{height}"
img.write "tmp/#{file_name}.png"
end
end
end
GenerateAppIconSizes.new(ARGV[0], ARGV[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment