【问题标题】:can't get image format - spawn EACCES error无法获取图像格式 - 产生 EACCES 错误
【发布时间】:2015-01-08 10:13:25
【问题描述】:

我正在使用 ImageMagicK for nodeJS (gm) 编写一个 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 以显示正确的错误消息。

【问题讨论】:

    标签: node.js node-gm


    【解决方案1】:

    您可以使用 'which' 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/
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-28
      • 1970-01-01
      • 2018-03-15
      • 2016-09-09
      • 2011-12-01
      • 2012-11-24
      • 2017-09-27
      相关资源
      最近更新 更多