Ionică Bizău
Ionică Bizău

Reputation: 113335

Convert and resize image to png using gm

I want to switch from Image Magick to Graphics Magick. The following code converts an image to PNG:

var ImageMagick = require("imagemagick");

// convert the image
ImageMagick.convert([
    "input.jpg"
  , '-resize'
  , "200x100"
  , "output.png"
], function(err, stdout){
    if (err) { throw err; }
    console.log(">> Done");
});

How can I do the same but using Graphics Magick?

Upvotes: 0

Views: 2592

Answers (1)

Ionică Bizău
Ionică Bizău

Reputation: 113335

Using resize and write methods:

var Gm = require("gm");

Gm("input.jpg").resize(200, 100, "!").write("output.png", function (err) {
    if (err) throw err;
    console.log('image converted.');
});

Note you have to install Graphics Magick binaries:

sudo apt-get install graphicsmagick
brew install graphicsmagick

Upvotes: 6

Related Questions