Inkscape has a shell mode called this way.
inkscape --shell
where you can execute commands as follows:
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 the elements in the file in the returned message, such as
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 advantage of this is that you can perform operations with SVG files without having to restart Inkscape every time.
I would like to do something like this:
sub do_inkscape { my ($file, $commands) = @_;
Everything works fine if I use open2 and formatting 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 figure out how to enter just one line, and capture only that output without having to restart Inkscape every time.
thanks
Simone