在一行中运行多个inkscape命令


Run multi inkscape commands in one line

是否可以在一个exec命令中运行多个命令?我需要从SVG文件中抓取一些图像,这种变体太慢了:

exec('inkscape file.svg --export-id=g123 --export-png=img1.png');
exec('inkscape file.svg --export-id=g124 --export-png=img2.png');
exec('inkscape file.svg --export-id=g125 --export-png=img3.png');

所以我需要在一行中完成所有内容。我已经试过了:

exec('inkscape file.svg --export-id=g125 --export-png=img3.png inkscape file.svg --export-id=g123 --export-png=img1.png');

但是这只提取最后一张图像。

exec()本身并不慢。但每次调用时,您首先启动Inkscape,执行操作,然后再次关闭它。这就是为什么要花这么长时间。

遗憾的是,Inkscape没有批处理模式。但是您可以使用Gimp,它可以批量执行相同的操作。

您可以在shell模式下运行Inkscape,并通过向其标准输入写入命令与它通信。如果您不想在PHP中实现它,您可以编写一个简单的shell包装器来实现它对你来说,例如:

#!/bin/bash
SVG="$1"
shift
(
while [ "$1" != "" ] ; do
  echo "'"--file=$SVG'" '"--export-id=$1'" '"--export-png=$2'""
  shift 2
done
echo "quit"
) | '
  /path/to/inkscape --shell 2>/dev/null

然后像这样使用

exec("/path/to/wrapper file.svg g123 img1.png g124 img2.png g125 img3.png");

exec()可能并不慢。服务器/inkscape很慢。