3

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?

Igor P.
  • 1,407
  • 2
  • 20
  • 34
  • Did you install imagemagick/graphicsmagick first as noted in the `gm` [readme](https://github.com/aheckmann/gm#getting-started)? If so, are you able to execute imagemagick/graphicsmagick manually from the shell prompt? – mscdex Nov 01 '14 at 22:14
  • Yes, both were installed. Sorry for asking but how can I execute it manually? – Igor P. Nov 01 '14 at 22:37
  • For graphicsmagick it's just `gm`. – mscdex Nov 01 '14 at 23:35
  • No, I can't start it manually. Getting the error: no such command. Maybe I need to set a PATH? – Igor P. Nov 02 '14 at 08:57

3 Answers3

5

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

Brian
  • 1,026
  • 1
  • 15
  • 25
1

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

Surya Purohit
  • 1,090
  • 1
  • 9
  • 29
0

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.

mscdex
  • 104,356
  • 15
  • 192
  • 153
  • I took those steps: reinstalled gm (sudo npm install gm) AND added /node_modules/gm to my PATH information (vim /etc/paths) but I still can neither run gm manually (same error as before) nor run my code (same error). – Igor P. Nov 02 '14 at 21:25
  • First of all, you shouldn't use `sudo` to install locally, just use `npm install gm`. The other issue is that I wasn't referring to the `gm` **module** being in your `PATH`, but the actual path to the `gm` **binary** (this is totally separate from the `gm` module in npm). The `gm` **binary** is the one you install from homebrew, macports, or compile and install from [source](http://sourceforge.net/projects/graphicsmagick/files/graphicsmagick/) for example. The `gm` npm module calls out to the `gm` **binary**, so the module won't work until the **binary** is installed properly. – mscdex Nov 02 '14 at 21:30
  • Thank you for that important clarification! I totally got lost here, as I thought I was handling an "ordinary" node module. Now that I am aware that I am (also) dealing with actual binaries that must be installed separately (not using npm!) I got it working now. Thanks again and sorry for goofing up. – Igor P. Nov 02 '14 at 22:11
  • But How to install those binaries? – AbdelHady Jan 04 '15 at 14:08