-
Notifications
You must be signed in to change notification settings - Fork 14
/
Rakefile
48 lines (42 loc) · 1.52 KB
/
Rakefile
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
#!/usr/bin/ruby
# -*- coding: UTF-8 -*-
require 'fileutils'
require 'rubygems'
TARGET = "../images"
RESIZE = 600
if File.exist?('/Applications/Inkscape.app/Contents/Resources/bin/inkscape')
CMD_INKSCAPE='/Applications/Inkscape.app/Contents/Resources/bin/inkscape'
else
CMD_INKSCAPE='inkscape'
end
CMD_IMGMAGICK='convert'
desc "export images, default: rake convert[../images,600]"
task :convert, :target, :width do |t, args|
args.with_defaults(:target => TARGET, :width => RESIZE)
FileList["**/*.svg", "**/*.xcf", "**/*.jpg", "**/*.png", "**/*.gif"].each do |source|
[".svg", ".png", ".gif", ".xcf"].each do |prefer|
if File.exists?(source.sub(/\.[^.]+$/, prefer))
source = source.sub(/\.[^.]+$/, prefer)
break
end
end
if source =~ /\.svg/
output = args[:target] + '/' + source.sub(/\.[^.]+$/, '.png')
command = "#{CMD_INKSCAPE} -w #{args[:width]} -f #{source} -e #{output}"
elsif source =~ /\.xcf/
output = args[:target] + '/' + source.sub(/\.[^.]+$/, '.png')
command = "#{CMD_IMGMAGICK} -auto-level -flatten -resize '#{args[:width]}>' #{source} #{output}"
elsif source =~ /\.(jpg|png|gif)/
output = args[:target] + '/' + source
command = "#{CMD_IMGMAGICK} -auto-level -resize '#{args[:width]}>' #{source} #{output}"
end
unless uptodate?(output, [source])
Dir.mkdir(File.dirname(output)) unless File.exists?(File.dirname(output))
sh command
File.utime(0, Time.now, output)
end
end
end
task :default do
system "rake -T"
end