Inkscape has a shell mode invoked like this
inkscape --shell
where you can execute commands like this:
some_svg_file.svg -e some_png_output.png -y 1.0 -b #ffffff -D -d 150
which will generate a PNG file, or like this:
/home/simone/some_text.svg -S
which gives you the bounding box of all elements in the file in the return message like this
svg2,0.72,-12.834,122.67281,12.942 layer1,0.72,-12.834,122.67281,12.942 text2985,0.72,-12.834,122.67281,12.942 tspan2987,0.72,-12.834,122.67281,12.942
The benefit of this is that you can perform operations on SVG files without having to restart Inkscape every time.
I would like to do something like this:
sub do_inkscape { my ($file, $commands) = @_; # capture output return $output }
Things work OK if I use open2 and forking like this:
use IPC::Open2; $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'inkscape --shell'); $\ = "\n"; $/ = ">"; my $out; open my $fh, '>', \$out; if (!defined($kidpid = fork())) { die "cannot fork: $!"; } elsif ($kidpid == 0) { while (<>) { print CHLD_IN $_; } } else { while (<CHLD_OUT>) { chop; s/\s*$//gmi; print "\"$_\""; } waitpid($kidpid, 0); }
but I can't find out how to input only one line, and capture only that output without having to restart Inkscape every time.
Thanks
Simone