0
我正在研究一个摄影社交媒体网站,我正在为每个图像生成缩略图。这些图像在页面上显示的尺寸相当大,因此质量不会降低太多(例如www.prsmphoto.com/user/tyler)。使用LWIP在NodeJS中生成缩略图
目前我用的是: image.scale(.15);
哪一个可以降低文件大小的体面工作。但是,这破坏了看起来很可怕的较小图像的质量。我应该如何处理这个问题?我有困难缠绕它。
我正在研究一个摄影社交媒体网站,我正在为每个图像生成缩略图。这些图像在页面上显示的尺寸相当大,因此质量不会降低太多(例如www.prsmphoto.com/user/tyler)。使用LWIP在NodeJS中生成缩略图
目前我用的是: image.scale(.15);
哪一个可以降低文件大小的体面工作。但是,这破坏了看起来很可怕的较小图像的质量。我应该如何处理这个问题?我有困难缠绕它。
尝试使用锐利或画布模块。
首先,他们比快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!
});