diff --git a/docs/changelog.md b/docs/changelog.md index ebe88344..68b6e986 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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) diff --git a/src/pipeline.cc b/src/pipeline.cc index 6430a7d3..15ab9103 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -205,7 +205,7 @@ class PipelineWorker : public Napi::AsyncWorker { if (jpegShrinkOnLoad > 1 && static_cast(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 || diff --git a/test/unit/webp.js b/test/unit/webp.js index ab7fc4c4..fbbb7ad2 100644 --- a/test/unit/webp.js +++ b/test/unit/webp.js @@ -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 });