Node.js: Error: spawn ENOENT while using GM module

那年仲夏 提交于 2019-12-13 15:06:25

问题


Even though this has been asked several times, none of the existing answers helped me out. Using a MEAN environment (on Mac OSX), I installed graphicsmagick using:

sudo npm install gm

Whenever I run the following script, I get this error:

{ [Error: spawn ENOENT] code: 'ENOENT', errno: 'ENOENT', syscall: 'spawn' }

This is the piece of code I am trying to run:

var gm = require('gm');    
//var gm = require('gm').subClass({ imageMagick: true }); //tried this one too 

    gm('./project/public/images/webshots/test1.jpg')
           .resize(320, 240)
           .write('./project/public/images/webshots/test2.jpg', function (err) {
        if (!err) console.log('done');
        if(err){
           console.log(err);   
        }
        });

Appropriate writing permissions were given by:

sudo chmod -R 777 ./project/public/images/webshots

I even tried several source/destination path combinations. What else could I have missed?


回答1:


The gm module can't find the path to the gm executable. So it sounds like your $PATH needs to be updated to include the path where graphicsmagick was installed to.




回答2:


It is looking for the gm(GraphicsMagick) binary

Install GraphicsMagick via PPA:

sudo add-apt-repository ppa:dhor/myway
sudo apt-get update
sudo apt-get install graphicsmagick

This worked for me




回答3:


This helped me solving this issue.

gm('./project/public/images/webshots/test1.jpg')
.options({imageMagick: true})
.resize(320, 240)
.write('./project/public/images/webshots/test2.jpg', function (err) {
    if (!err) console.log('done');
    if(err){
       console.log(err);   
    }
});

Note: imageMagick should be installed



来源:https://stackoverflow.com/questions/26693769/node-js-error-spawn-enoent-while-using-gm-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!