问题
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