Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: spawn ENOENT while using GM in node

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

like image 721
Olivier_s_j Avatar asked Apr 25 '13 18:04

Olivier_s_j


2 Answers

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 });
    
like image 180
Quỳnh Lê Avatar answered Nov 13 '22 02:11

Quỳnh Lê


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 });
like image 10
Matiss Avatar answered Nov 13 '22 03:11

Matiss