Skip to content

Commit

Permalink
Use vips scaling for webp fixes #3262
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha committed Jun 17, 2022
1 parent 4662527 commit 2cb5eb8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class PipelineWorker : public Napi::AsyncWorker {
->set("access", baton->input->access)
->set("scale", scale)
->set("fail_on", baton->input->failOn);
if (inputImageType == sharp::ImageType::WEBP) {
if (scale < 1.0 && inputImageType == sharp::ImageType::WEBP) {
option->set("n", baton->input->pages);
option->set("page", baton->input->page);

Expand Down
14 changes: 14 additions & 0 deletions test/unit/resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ describe('Resize dimensions', function () {
});
});

it('Webp resize then extract large image', function (done) {
sharp(fixtures.inputWebP)
.resize(0x4000, 0x4000)
.extract({ top: 0x2000, left: 0x2000, width: 256, height: 256 })
.webp()
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual('webp', info.format);
assert.strictEqual(256, info.width);
assert.strictEqual(256, info.height);
done();
});
});

it('WebP shrink-on-load rounds to zero, ensure recalculation is correct', function (done) {
sharp(fixtures.inputJpg)
.resize(1080, 607)
Expand Down

0 comments on commit 2cb5eb8

Please sign in to comment.