问题
When I try to resize an image like this:
gm('public/uploads/1710410635.jpg')
.resize(240, 240)
.noProfile()
.write('public/uploads/1710410635_t.jpg', function (err) {
if (!err) console.log('done');
});
I get this error:
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:945:11)
at Process.ChildProcess._handle.onexit (child_process.js:736:34)
My file structure is as follows:

The code is executed in the postnewsitem.js
file
why is this error occurring & how do I solve it ?
edit: GraphicsMagick works, proof:

回答1:
Install ImageMagick and use subClass imageMagick.
Install ImageMagick
sudo apt-get install imagemagick
using subClass imagemagick:
var gm = require('gm').subClass({ imageMagick: true });
回答2:
I'm running nodejs on windows 7 with installed gm and imagemagick and seems that there was conflict between both modules so i googled a bit and found out how to avoit that. I added this line and that solved my ENOENT problem:
var imageMagick = gm.subClass({ imageMagick: true });
so the code now looks like this:
var gm = require('gm');
var imageMagick = gm.subClass({ imageMagick: true });
imageMagick('test/pig.jpg').rotate('green', 45).write('test/crazy_pig.jpg', function (err) {
if (!err) console.log('crazy pig has arrived');
else console.log(err);
})
OR you can do that when requiring gm, like so:
var gm = require('gm').subClass({ imageMagick: true });
回答3:
Had the same problem with Node.js application running on Windows using IIS. Problem has gone when I set "Load User Profile" option in "Advanced settings" of appropriate AppPool to "True"
回答4:
I faced the same problem and solved it in the given way.
var gm = require('gm');
gm('public/uploads/1710410635.jpg').options({imageMagick: true}).resize(240,240).write('public/uploads/1710410635.jpg', function (err) {
if (!err) console.log('Done');
else console.log(err);
})
Note: If you haven't installed imageMagick. Please install that first
回答5:
Another scenario where this might happen (when using windows) is if you try to run your code from a UNC Path. mapping a drive letter and running over the mapped drive letter solves this problem as well.
回答6:
I have the same issue as you and this was SOLUTION. ImageMagick was working correctly in terminal/console but not in nodejs (gm module). After 2 days of losing hair i fixed it by adding PATH variable to environment variables process.env.PATH There should be path to your imagemagick and other executables. Node.js has some PATH from system but for some reasone GM is ignoring it and using process.env.PATH
I created environment variable PATH(process.env.PATH) and set value to bin:node_modules/.bin:/usr/local/bin:/usr/bin:/bin I'm using MAC OS X
I got imageMagick installed with brew (brew install imagemagick
)
回答7:
Because I found this problem many times here on stackoverflow, I want to share this answer: https://stackoverflow.com/a/25461564/3970623
The "spawn ENOENT" seems to be caused by a valid unix tools installation which is accessible using PATH environment variable.
回答8:
In my case it was very simple. It ocurred rigth after instalation of GraphicsMagick in windows 10: I tryed using a console that was yet open before installing GraphicsMagick. Therefore it used old path information and didn´t found GraphicsMagick. Solution: I had to open a new console for running the node for using gm.
回答9:
/gm/lib/command.js have an option where you can set the appPath, if gm is already working through the terminal, you can get the path to gm and pass it via the subClass function,In my case gm was installed in /usr/local/bin/ using brew on MacOsx.
var gm = require('gm').subClass({ appPath: "/usr/local/bin/" });
回答10:
Just in case someone is finding this error while on macOS, this worked for me:
$ brew install graphicsmagick
来源:https://stackoverflow.com/questions/16222116/error-spawn-enoent-while-using-gm-in-node