2
Inkscape中的Inkscape的外殼援引這樣使用從perl的
inkscape --shell
在那裏你可以這樣執行命令的shell模式:
some_svg_file.svg -e some_png_output.png -y 1.0 -b #ffffff -D -d 150
,這將產生一個PNG文件,或者是這樣的:
/home/simone/some_text.svg -S
它給你在文件中的所有元素的邊界框在這樣的返回消息中
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
這樣做的好處是,你可以對SVG文件的操作,而無需重新啓動Inkscape的每一次。
我願做這樣的事情:
sub do_inkscape {
my ($file, $commands) = @_;
# capture output
return $output
}
事情工作確定,如果我使用open2和分叉這樣的:
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);
}
,但我不能找出如何只輸入一行,並且只捕獲該輸出,而不必每次都重新啓動Inkscape。
感謝
西蒙娜