Last active
February 2, 2016 01:38
-
-
Save unRob/429ee0d74b557a9f73c6 to your computer and use it in GitHub Desktop.
Convierte una imagen en un archivo .icns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
src = ARGV[0] | |
if src == '' | |
puts "Usage: ./iconiza take five.jpg" | |
puts "Convierte una imagen en un archivo .icns" | |
end | |
name = src.split('.') | |
name.pop | |
name = name.join('.') | |
dst = File.dirname( File.expand_path src)+"/#{name}.iconset" | |
unless File.directory? dst | |
Dir.mkdir dst | |
end | |
resoluciones = [ | |
[1024, '512x512@2x'], | |
[512 , '512x512'], | |
[512, '256x256@2x'], | |
[256 , '256x256'], | |
[256, '128x128@2x'], | |
[128, '128x128'], | |
[64, '32x32@2x'], | |
[32, '16x16@2x'], | |
[32, '32x32'], | |
[16, '16x16'] | |
] | |
resoluciones.each do |r| | |
res, name = r | |
puts "Creando #{name}.png (#{res}x#{res})" | |
cmd = "convert '#{src}' -resize #{res}x#{res}^ -background none -depth 24 -gravity center -extent #{res}x#{res} '#{dst}/icon_#{name}.png'" | |
system cmd | |
end | |
`iconutil -c icns "#{dst}"` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment