]> CyberLeo.Net >> Repos - CDN/www.cyberleo.net.git/blob - lib/svg2png.rb
Palette-reduce and crush PNG generated from SVG
[CDN/www.cyberleo.net.git] / lib / svg2png.rb
1 require 'tempfile'
2
3 class Svg2Png < Nanoc::Filter
4   identifier :svg2png
5   type :binary
6   def run(filename, params={})
7     temp = Tempfile.new(File.basename(filename))
8     raise Exception unless system("inkscape '--export-png=#{temp.path}' '#{filename}' >/dev/null")
9     raise Exception unless system("convert '#{temp.path}' +dither -colors 256 '#{temp.path}'")
10     raise Exception unless system("pngcrush -brute -q '#{temp.path}' '#{output_filename}'")
11   end
12 end