I'm developing a similar service of Imgix and I'm using Sharp.
But the webp lossless compression Imgix get better results than Sharp. The same image with the same width and height in Imgix have 453 KB and with Sharp 1.3 MB.
Some recommendation to increase compression without losing quality?
The code that I'm using:
https.get(url, function (response) {
let transform = sharp().toFormat('webp').resize(width, height);
return response.pipe(transform).webp({lossless:true}).pipe(res);
});
I see that document have some fileds in options: quality, alphaQuality, nearLossless, force. Can you try it? And compare with IMGIX
- quality: Number quality, integer 1-100 (optional, default 80)
- alphaQuality: Number quality of alpha layer, integer 0-100 (optional, default 100)
- lossless: Boolean use lossless compression mode (optional, default false)
- nearLossless: Boolean use near_lossless compression mode (optional, default false)
- force: Boolean force WebP output, otherwise attempt to use input format (optional, default true)
https.get(url, function (response) {
let transform = sharp().toFormat('webp').resize(width, height);
return response.pipe(transform).webp({lossless:true, quality: 60, alphaQuality: 80, force: false}).pipe(res);
});
Documentation on how to use Sharp's webp output options is non-existent AFAICT, but according to this comment the options nearLossless and quality should be used together, while the lossless:true option is equivalent to nearLossless:true,quality:100
In my experience, nearLossless:true,quality:50 will cut the file size to less than half of lossless:true, while retaining most of the quality.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With