]> git.draconx.ca Git - homepage.git/blob - lib/svg2png.rb
cdecl99-1.3 bash-5 hotfix
[homepage.git] / lib / svg2png.rb
1 # Nick's web site: svg2png filter: convert SVG to PNG using rsvg-convert.
2 #
3 # Copyright © 2021 Nick Bowler
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
18 class SVG2PNG < Nanoc::Filter
19     identifier :svg2png
20     type :text => :binary
21
22     def run(content, params = {})
23         args = ["-o", output_filename]
24         params.each do |key, val|
25             next if !val
26
27             args << "--#{key.to_s.gsub("_", "-")}"
28             if val != true then args << val.to_s end
29         end
30
31         dummy, status = Open3.capture2("rsvg-convert", *args,
32                                        stdin_data: content)
33         raise "rsvg-convert failed" if status != 0
34     end
35 end