node.js到imagemagick命令中断(node.js to imagemagick command breaking)

我通过node.js调用一个imagemagick脚本,命令正在破坏,但我无法弄清楚原因。

我正在尝试做的简单示例:

var spawn = require('child_process').spawn, ls = spawn('convert', ['-size', '168x45', 'xc:transparent', '-draw', '"image over 0,0 0,0 \'/path/to/img1.png\'"', '/path/to/out.png']); ls.stderr.on('data', function (data) { console.log('stderr: ' + data); });

如果我运行那个确切的命令(唯一改变的是路径,因为它们是绝对的),我得到了stderr:

"convert: non-conforming drawing primitive definition `image over 0,0 0,0 '/path/to/img1.png'' @ error/draw.c/DrawImage/3145."

根据一些论坛,通常意味着IM无法打开图像,因为路径无效等等...现在奇怪的是,如果我将convert为echo和prepend convert我会得到以下命令:

convert -size 168x45 xc:transparent -draw "image over 0,0 0,0 '/path/to/img1.png'" /path/to/out.png

从bash直接运行时效果很好。

有任何想法吗?

更多信息:

我只是从图像目录中尝试了这个,并删除了路径(所以它的image over ... img1.png ),我得到了同样的错误。 以同样的方式运行pwd给了我相应的目录

I'm calling an imagemagick script via node.js and the command is breaking, but I can't figure out why.

A simplified example of exactly what I'm trying to do:

var spawn = require('child_process').spawn, ls = spawn('convert', ['-size', '168x45', 'xc:transparent', '-draw', '"image over 0,0 0,0 \'/path/to/img1.png\'"', '/path/to/out.png']); ls.stderr.on('data', function (data) { console.log('stderr: ' + data); });

If I run that exact command (the only thing changed are the paths since they're absolute), I get, on stderr:

"convert: non-conforming drawing primitive definition `image over 0,0 0,0 '/path/to/img1.png'' @ error/draw.c/DrawImage/3145."

Which, according to some forums, usually means that IM can't open the image due to having an invalid path, etc... Now the odd thing is that if I change the convert to echo and prepend convert I get the following command:

convert -size 168x45 xc:transparent -draw "image over 0,0 0,0 '/path/to/img1.png'" /path/to/out.png

which works perfectly when run directly from bash.

Any ideas?

more info:

I just tried this from the directory of the image, and removed the path (so it's image over ... img1.png), and I get the same error. running pwd the same way gives me the appropriate directory

最满意答案

找到答案: http : //shchekoldin.com/2009/10/13/imagemagick-convert-problem/

仍然不知道发生了什么,但只是简单地创建一个shell脚本:

eval 'convert '$@

并运行该命令(而不是convert )解决问题。 跆拳道???

Found an answer: http://shchekoldin.com/2009/10/13/imagemagick-convert-problem/

Still no clue what's happening, but creating a shell script with simply:

eval 'convert '$@

and running that as the command (instead of convert) solves the issue. wtf???

更多推荐