Use polaroid effect in node.js imageMagick

341 views Asked by At

In the terminal I can use the following snippet to create an image with a "polaroid design" (see http://www.imagemagick.org/Usage/thumbnails/#polaroid).

convert -caption 'mycaption' myimage.jpeg  -thumbnail 250x250 \
    -bordercolor Lavender  -background gray40  -gravity South \
    -font "Helvetica.ttf" -pointsize 12  -density 144 +polaroid \
     polaroid.jpeg

How would I accomplish this in the node version of imageMagick/gm (https://github.com/aheckmann/gm)?

var gm = require('gm');
var fs = require('fs');
var imageMagick = gm.subClass({ imageMagick: true });

imageMagick("myimage.jpeg")
    .resize(250, 250)
    //CREATE POLAROID HERE SOMEHOW???
    .write("polaroid.jpeg", function (err) {});

Thanks for any hints!

1

There are 1 answers

0
Miriam On

Use gm().command(), gm().in(), and gm().out (see https://github.com/aheckmann/gm#custom-arguments)

var gm = require('gm');
var fs = require('fs');
var imageMagick = gm.subClass({ imageMagick: true });

imageMagick()
  .command("convert")
  .in("-caption",  "mycaption")
  .in("myimage.jpeg")
  .in("-thumbnail",  "250x250")
  .in("+polaroid")
   // insert other options...
  .write("polaroid.jpeg", function (err) {
     if (err) return console.log(err);
  });