0

如何使用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)
4

1 回答 1

4

我真的不会说话node,但它可能与此类似:

im.convert(['input.jpg', '-gravity', 'center', '-background','white', '-extent', '600x200','result.jpg'], 
function(err, stdout){
  if (err) throw err;
  console.log('stdout:', stdout);
});
于 2016-09-30T12:51:33.540 回答