使用gm将图像转换为png并将其调整为png [英] Convert and resize image to png using gm
本文介绍了使用gm将图像转换为png并将其调整为png的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从Image Magick切换到 Graphics Magick 。以下代码将图像转换为PNG:
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");
});
我怎么能这样做但是使用Graphics Magick?
How can I do the same but using Graphics Magick?
推荐答案
使用调整大小
和编写
方法:
var Gm = require("gm");
Gm("input.jpg").resize(200, 100, "!").write("output.png", function (err) {
if (err) throw err;
console.log('image converted.');
});
注意你必须安装Graphics Magick二进制文件:
Note you have to install Graphics Magick binaries:
sudo apt-get install graphicsmagick
brew install graphicsmagick
这篇关于使用gm将图像转换为png并将其调整为png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文