Convert and resize image to png using gm

隐身守侯 提交于 2020-01-06 13:59:08

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/27340632/convert-and-resize-image-to-png-using-gm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!