如何使用https://github.com/rsms/node-imagemagick在图像周围添加更多空白?例如原始图像是width:300, height:100
,我想生成新图像是width: 600, height: 200
原始图像在中心保持原始大小,在周围添加空白区域成为新图像..
我尝试了下面的代码,但这会使原始图像变为 600*200 ...如何解决?
function cropGravity(srcFilePath, dstFilePath, resizeWidth, resizeHeight, quality, gravity) {
return new Promise(function (resolve, reject){
im.crop({
srcPath: srcFilePath,
dstPath: dstFilePath,
width: resizeWidth,
height: resizeHeight,
quality: quality,
gravity: gravity
}, function(error, stdout, stderr){
if (error != null) {
console.log(error)
reject(error);
} else {
resolve(dstFilePath);
}
});
});
};
...
var resizeWidth = 600;
var resizeHeight = 200;
var quality = 1;
var gravity = 'Center';
cropGravity(srcFilePath, dstFilePath, resizeWidth, resizeHeight, quality, gravity)