Search code examples
node.jsubuntuimagemagickcommand-line-interfacegraphicsmagick

GraphicsMagick + ImageMagick + rejection Error: Command failed:


The version of gm used is the latest 1.9.0.

node version is 0.12.0.

gm is initialized with the { imageMagick: true } flag. ImageMagick is also updated. The server facing this problem is Ubuntu.

Principally, I believe the problem is caused by user rights. The application works when it is run on root user. However, when running in another user safeuser, the error occurs. It is trying to do a series of resizing etc like this:

gm(imagePath)
    .resize(size, size)
    .quality(quality)
    .writeAsync(path + suffix).catch(function(err) { // note #writeAsync is promisification
        throw (err); //don't swallow the error
    });

There are a lot of documentation out there that seeks to resolve errors to do with access privileges. However, it wasn't clear on how, in this situation where my Node instance is running on safeuser, as to how it could be given access to the ImageMagick CLI suite. Also, safeuser was able to do filesystem operations as the folders was CHOWN'ed to it. So that part of suspicion is removed.

Any help please?


Solution

  • error was not related to permissions apparently.

    Resolved by using GraphicsMagick's own CLI over imageMagick:

    var gm = require('gm').subclass({imageMagick: true}); // remove this subclass to use gm's own CLI
    

    var gm = require('gm')

    How to install gm on ubuntu:

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