0

我在一个摄影社交媒体网站上工作,我正在为每张图片生成缩略图。图像在页面上以合适的尺寸显示,因此质量不能降低太多(例如 www.prsmphoto.com/user/tyler)。

目前我正在使用这个:image.scale(.15);

这在降低文件大小方面做得不错。但是,这会破坏看起来很糟糕的较小图像的质量。我应该如何处理这个?我很难绕过它。

4

1 回答 1

0

尝试使用sharp或canvas模块。

首先,它们比 lwip 快 6-8 倍:https ://github.com/ivanoff/images-manipulation-performance

然后,您可以保存所需质量的文件:

var stream = canvas.jpegStream({
  quality: 80 // JPEG quality (0-100) default: 75
});
sharp('input.png')
  .rotate(180)
  .resize(300)
  .flatten()
  .background('#ff6600')
  .overlayWith('overlay.png', { gravity: sharp.gravity.southeast } )
  .sharpen()
  .withMetadata()
  .quality(90)
  .webp()
  .toBuffer()
  .then(function(outputBuffer) {
    // outputBuffer contains upside down, 300px wide, alpha channel flattened
    // onto orange background, composited with overlay.png with SE gravity,
    // sharpened, with metadata, 90% quality WebP image data. Phew!
  });
于 2016-07-19T06:02:41.240 回答