Search code examples
node.jsgraphicsmagick

using node.js with a remote GraphicsMagick server


I have node.js installed on one server. I have graphicsmagick https://github.com/aheckmann/gm installed on another server. The graphics files themselves are also stored on the graphicsmagick server. I want to install & setup the node gm module so that the work/processing is done on the graphicsmagick server. However, after reading through the documentation, I don't see how to do this. Of course, I can install graphicsmagic on the same server as node, and have it work properly. But I don't want to have the heavy image processing happening on the same server as node. Is this possible to separate the two?


Solution

  • the gm module is not a server, you need to write a service to manipulate the images with gm.

    Something like this using express.js:

    var express = require('express');
    
    var app = express.createServer();
    
    app.get('/:image', function (req, res, next) {
      // set headers here
    
      gm('/path/to/my/' + req.params.image)
        .resize('200', '200')
        .stream(function (err, stdout, stderr) {
          if (err) next(err);
          stdout.pipe(res);
        });
    });
    
    app.listen(8000);