Respect fastShrinkOnLoad option for WebP input #3516

This commit is contained in:
Lovell Fuller 2023-01-17 09:39:23 +00:00
parent 9f79f80a93
commit c150263ef1
3 changed files with 12 additions and 1 deletions

View File

@ -32,6 +32,9 @@ Requires libvips v8.14.0
[#3470](https://github.com/lovell/sharp/pull/3470)
[@ejoebstl](https://github.com/ejoebstl)
* Respect `fastShrinkOnLoad` resize option for WebP input.
[#3516](https://github.com/lovell/sharp/issues/3516)
* Reduce sharpen `sigma` maximum from 10000 to 10.
[#3521](https://github.com/lovell/sharp/issues/3521)

View File

@ -205,7 +205,7 @@ class PipelineWorker : public Napi::AsyncWorker {
if (jpegShrinkOnLoad > 1 && static_cast<int>(shrink) == jpegShrinkOnLoad) {
jpegShrinkOnLoad /= 2;
}
} else if (inputImageType == sharp::ImageType::WEBP && shrink > 1.0) {
} else if (inputImageType == sharp::ImageType::WEBP && baton->fastShrinkOnLoad && shrink > 1.0) {
// Avoid upscaling via webp
scale = 1.0 / shrink;
} else if (inputImageType == sharp::ImageType::SVG ||

View File

@ -115,6 +115,14 @@ describe('WebP', function () {
)
);
it('should produce different file size with/out shrink-on-load', async () => {
const [shrunk, resized] = await Promise.all([
sharp(fixtures.inputWebP).resize({ width: 16 }).toBuffer(),
sharp(fixtures.inputWebP).resize({ width: 16, fastShrinkOnLoad: false, kernel: 'nearest' }).toBuffer()
]);
assert.notStrictEqual(shrunk.length, resized.length);
});
it('invalid effort throws', () => {
assert.throws(() => {
sharp().webp({ effort: true });