34

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:

enter image description here

The code is executed in the postnewsitem.js file

why is this error occurring & how do I solve it ?

edit: GraphicsMagick works, proof:

enter image description here

8
  • Did you install GraphicsMagick? Also, what platform are you using? GM is only tested on Mac OS X and Ubuntu.
    – robertklep
    Apr 25, 2013 at 18:37
  • yes I have graphicsmagic 1.3.18 working on Lion OS X . ( Though it says: "imagemagick-6.8.0-10 already installed, it's just not linked", when trying to see if it is really installed.) Apr 25, 2013 at 18:42
  • GraphicsMagick isn't the same as ImageMagick. You need to configure gm to get it to work with ImageMagick. It looks like the gm module can't find the GM/IM binaries, they have to be somewhere in your $PATH I think.
    – robertklep
    Apr 25, 2013 at 18:48
  • I installed graphicsmagic instead now, though the error remains. ( If I type gm in the terminal I see that it is installed.) Apr 25, 2013 at 18:53
  • 1
    off topic: @ojtwist , what IDE is the screenshot taken from ?
    – epeleg
    Jun 28, 2013 at 8:25

10 Answers 10

67

Install ImageMagick and use subClass imageMagick.

  1. Install ImageMagick

    sudo apt-get install imagemagick
    
  2. using subClass imagemagick:

    var gm = require('gm').subClass({ imageMagick: true });
    
5
  • Thanks, This resolved issue of my nodejs app on heroku.
    – Devesh
    Sep 4, 2014 at 6:11
  • 1
    GM also requires GraphicsMagick like in GM's Readme file is mentioned. When I installed it, the issue disappeared. In Mac OS X, brew install graphicsmagick.
    – cespon
    Jan 12, 2015 at 11:04
  • 1
    To CentOS guys : yum install ImageMagick
    – yangsibai
    Feb 6, 2015 at 9:28
  • This should be be marked as the correct answer. Thanks a bunch!
    – jwanglof
    Nov 13, 2015 at 13:18
  • sudo apt-get install imagemagick + sudo apt-get install graphicsmagick worked for me Jun 28, 2018 at 1:05
10

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 });
1
  • 1
    I can confirm that this solved my problem on OSX Mountain Lion. I installed it using macports instead of brew, In case this can help someone
    – roy riojas
    Oct 21, 2013 at 18:48
4

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"

1
  • OMG! Thank you sooooo much. Spent so long trying to figure this out. How you figured it out is beyond me, but thank you! Apr 29, 2014 at 15:49
2

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

1

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.

2
  • Can you give example? What do you mean with running over?
    – Matiss
    Aug 27, 2013 at 10:08
  • maybe "running over" is not the right term. I meant that your node.exe should be run from something like n:\node\node.exe and not from something like \\myserver\myshare\node\node.exe
    – epeleg
    Aug 28, 2013 at 6:32
1

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)

0

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.

0

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.

0

/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/" });
0

Just in case someone is finding this error while on macOS, this worked for me:

$ brew install graphicsmagick

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.