-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_imageMaciek.rb
executable file
·66 lines (52 loc) · 1.55 KB
/
_imageMaciek.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
65
#!/usr/bin/env ruby
# The resizing is done by calling the command line tools of image magick,
# because trying to get the ruby gem to work was taking too much time.
require 'rubygems'
require 'csv'
def convert(file_name, width, suffix)
system "convert " + file_name + ".png -strip -resize " + width.to_s + " _converted/" + file_name + suffix + ".png"
end
config_file = File.open('_imageConfig.txt', 'r')
types = Hash.new
files = Array.new
state = :null
config_file.each_line do |line|
line.strip!
if line[0] == '#' || line.length == 0
elsif line.start_with?(":types")
state = :types
elsif line.start_with?(":files")
state = :files
else
list = line.parse_csv
if state == :types
types[list[0].strip] = {:iphone => list[1].to_i, :ipad => list[2].to_i}
elsif state == :files
files.push({:file => list[0].strip, :type => list[1].strip})
else
puts "wrong format at line " + line
end
end
end
puts files.length.to_s + " file(s) to convert..."
puts
if !(File.directory? "_converted")
Dir.mkdir "_converted"
end
files.each do |file|
Dir.glob(file[:file]).each do |filename| # expand the globs
puts filename + "..."
filename = File.basename(filename, '.png')
type_def = types[file[:type]]
if type_def[:iphone] != 0
convert(filename, type_def[:iphone] * 2, "@2x")
convert(filename, type_def[:iphone], "")
end
if type_def[:ipad] != 0
convert(filename, type_def[:ipad] * 2, "@2x~ipad")
convert(filename, type_def[:ipad], "~ipad")
end
end
end
puts
puts "Done!"