require 'tempfile' class Svg2Png < Nanoc::Filter identifier :svg2png type :binary def run(filename, params={}) temp = Tempfile.new(File.basename(filename)) raise Exception unless system("inkscape '--export-png=#{temp.path}' '#{filename}' >/dev/null") raise Exception unless system("convert '#{temp.path}' +dither -colors 256 '#{temp.path}'") raise Exception unless system("pngcrush -brute -q '#{temp.path}' '#{output_filename}'") end end