From a2696ecce7930af31fbae087c966a501ebfdf483 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Tue, 26 Apr 2016 17:46:29 -0500 Subject: [PATCH] Palette-reduce and crush PNG generated from SVG --- lib/svg2png.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/svg2png.rb b/lib/svg2png.rb index 571c5b0..2610892 100644 --- a/lib/svg2png.rb +++ b/lib/svg2png.rb @@ -1,7 +1,12 @@ +require 'tempfile' + class Svg2Png < Nanoc::Filter identifier :svg2png type :binary def run(filename, params={}) - raise Exception unless system("inkscape '--export-png=#{output_filename}' '#{filename}'") + 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 -- 2.42.0