imagemagick

Server side image processing using node.js and imagemagick.

There are 2 snippets with the imagemagick tag

  • Crop an Image using ImageMagick and node.js

    Crop an image using node.js and the imagemagick node module. The module's convert method is used, where native ImageMagick arguments are passed in as an array. Size, offset and an input image path are supplied to produce a cropped output PNG, which is written to file.

    var http = require("http");
    var im = require("imagemagick"); 
    
    var args = [
      "image.png",
      "-crop",
      "120x80+30+15",
      "output.png"
    ];
    
    var server = http.createServer(function(req, res) {
    
      im.convert(args, function(err) {
        if(err) { throw err; }
        res.end("Image crop complete");
      });
    
    }).listen(8080);
    26 Aug 2013
  • Resize an Image using ImageMagick and node.js

    A simple example showing how to resize an image using the imagemagick module.

    var http = require("http");
    var im = require("imagemagick"); 
    
    var server = http.createServer(function(req, res) {
    
      var options = {
        width: 120,
        height: 80,
        srcPath: "image.png",
        dstPath: "output.png"
      };
    
      im.resize(options, function(err) {
        if(err) { throw err; }
        res.end("Image resize complete");
      });
    
    }).listen(8080);
    27 Aug 2013