19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/mcicons/command.rb', line 19
def execute
option = {}
OptionParser.new do |opt|
opt.on('-i Image PATH', 'Image Path') { |v| option[:i] = v }
opt.on('-o Outputs PATH', 'Outputs Icons Path') { |v| option[:o] = v }
opt.parse!(ARGV)
end
image_path = option[:i]
dir_path = File.dirname(image_path)
output_path = option[:o].nil? ? dir_path : option[:o]
tmp_path = "#{output_path}/app.iconset"
Dir.mkdir(tmp_path, 999) unless FileTest.exist?(tmp_path)
@counter = 0
puts 'conversion start'
SIZE_LIST.each do |r|
image = MiniMagick::Image.open(image_path)
image.format 'png'
image.resize "#{r}x#{r}!"
image.write "#{tmp_path}/icon_#{r}x#{r}.png"
retina_image = MiniMagick::Image.open(image_path)
retina = r.to_i * 2
retina_image.format 'png'
retina_image.resize " #{retina}x#{retina}!"
retina_image.write "#{tmp_path}/icon_#{r}x#{r}@2x.png"
@counter += 100 / SIZE_LIST.count
puts "#{@counter}% complete."
end
puts '100% conversion complete'
system("iconutil -c icns #{tmp_path}")
system("rm -rf #{tmp_path}")
puts 'created icons file'
end
|