开发者

Run multi inkscape commands in one line

Is it possible to run multiple commands in one exec command? I need to grab some images from SVG files and this varia开发者_运维知识库nt is too slow:

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');

So I need to do everything in one line. I've already tried this:

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

But this extracts only the last image.


exec() itself is not slow. But with each call, you first start Inkscape, perform the operation and close it again. That is, what takes so long.

Unfortunately, Inkscape doesn't have a batch mode. Bu you could use Gimp, which can do the same operation in batch.


You can run Inkscape in shell mode and communicate with it by writing commands to its stdin. If you don't want to implement it in PHP you could write a simple shell wrapper that does it for you, e.g:

#!/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

And then use it like this

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


exec() is probably not slow. Server/inkscape is slow.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜