我正在为NodeJS(gm)使用ImageMagicK编写一个NodeJs 0.10应用程序
我使用restify来创建API。
我试图通过检查其格式来确定上传的文件是否为图像。
我正在使用上传的图片路径来获取request.files.drink_image.path
结果/tmp/upload_72052b3fede5faccfe4cf20b59b341f2
该文件上ls -lsa的结果:
-rw-r--r-- 1 ufk users 8255 Jan 8 12:02 /tmp/upload_8ee3f234f8c04c67430f28f1336e9ba6
该文件上文件的结果:
/tmp/upload_8ee3f234f8c04c67430f28f1336e9ba6: PNG image data, 250 x 100, 8-bit/color RGB, non-interlaced
我正在从用户ufk运行nodeJS。
当我尝试使用以下代码获取格式时:
gm(tempFilePath).format(function(err, value){
console.log(inspect(err));
console.log(value);
});
我收到以下错误:
{ [Error: spawn EACCES] code: 'EACCES', errno: 'EACCES', syscall: 'spawn' }
我不知道为什么我会因为用户ufk创建访问错误而将其设置为rw
。
有任何想法吗?
好的,我没有安装ImageMagick或GraphicsMagick。现在可以了!但是如何从nodeJS中检查是否已安装ImageMagick或GraphicsMagicK,以便显示正确的错误消息。
您可以使用“哪个” shell命令来检查“ gm”可执行文件。尝试https://github.com/arturadib/shelljs:
if (!which('gm')) {
// gm is not installed
// return error message
}
您可以走得更远,确保这是正确的可执行文件:
var e = exec('gm -version');
if (e.code !== 0) {
// error
}
// parse e.output to make sure the right version is installed
// e.g. GraphicsMagick 1.3.18 2013-03-10 Q16 http://www.GraphicsMagick.org/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句