-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflat_ico.rb
60 lines (49 loc) · 1.92 KB
/
flat_ico.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
require 'json'
ontology = ARGV[0]
ontology = JSON.parse(File.read(ontology))
input = ARGV[1]
`
rm -fr /tmp/ico_i && mkdir /tmp/ico_i
rm -fr /tmp/ico && mkdir /tmp/ico
`
Dir.chdir(input)
Dir.glob('**/*.svg').each{ |icon|
superclass = icon.gsub('.svg', '').split('/')[0]
out = icon.gsub('.svg', '').gsub('/', '-')
puts([icon, superclass, out].inspect)
wh = `identify -format '%w-%h' "#{icon}"`
w, h = wh.split('-').map(&:to_f)
resize = h > w ? '-h' : '-w'
out_p = "#{out}•.svg"
`
rsvg-convert --keep-aspect-ratio #{resize} 11 -f svg "#{icon}" -o "/tmp/ico/#{out_p}"
sed -i 's/fill="[^"]*"/fill="rgb(30%,30%,30%)"/g' "/tmp/ico/#{out_p}"
`
color_fill = ontology['superclass'][superclass]['color_fill']
color_line = ontology['superclass'][superclass]['color_line']
out_b = "#{out}◯.svg"
out_w = "#{out}⬤.svg"
`
rsvg-convert --keep-aspect-ratio #{resize} 17 -f svg "#{icon}" -o "/tmp/ico_i/#{out_b}"
`
wh = `identify -format '%w-%h' "/tmp/ico_i/#{out_b}"`
w, h = wh.split('-').map(&:to_f)
x = (30 - w) / 2
y = (30 - h) / 2
File.new("/tmp/ico/#{out_b}", 'w').write(
File.read('../container.svg')
.gsub('<g transform="translate(1,1)"></g>', '<g transform="translate(1,1)">' + File.readlines("/tmp/ico_i/#{out_b}")[2..-2].join + '</g>')
.gsub(/fill="[^"]*"/, 'fill="rgb(30%,30%,30%)"')
.gsub('translate(1,1)', "translate(#{x},#{y})")
.gsub('#ff0000', color_line)
.gsub('#00ff00', '#ffffff')
)
File.new("/tmp/ico/#{out_w}", 'w').write(
File.read('../container.svg')
.gsub('<g transform="translate(1,1)"></g>', '<g transform="translate(1,1)">' + File.readlines("/tmp/ico_i/#{out_b}")[2..-2].join + '</g>')
.gsub(/fill="[^"]*"/, 'fill="#FFFFFF"')
.gsub('translate(1,1)', "translate(#{x},#{y})")
.gsub('#00ff00', color_fill)
.gsub('#ff0000', '#ffffff')
)
}