Skip to content

Commit

Permalink
Respect fastShrinkOnLoad option for WebP input #3516
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Jan 17, 2023
1 parent 9f79f80 commit c150263
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
8 changes: 8 additions & 0 deletions test/unit/webp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit c150263

Please sign in to comment.