mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Prevent upsampling via libwebp (#3267)
This commit is contained in:
parent
4662527a17
commit
a333b87f5d
@ -188,8 +188,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
if (jpegShrinkOnLoad > 1 && static_cast<int>(shrink) == jpegShrinkOnLoad) {
|
if (jpegShrinkOnLoad > 1 && static_cast<int>(shrink) == jpegShrinkOnLoad) {
|
||||||
jpegShrinkOnLoad /= 2;
|
jpegShrinkOnLoad /= 2;
|
||||||
}
|
}
|
||||||
} else if (inputImageType == sharp::ImageType::WEBP ||
|
} else if (inputImageType == sharp::ImageType::WEBP && shrink > 1.0) {
|
||||||
inputImageType == sharp::ImageType::SVG ||
|
// Avoid upscaling via webp
|
||||||
|
scale = 1.0 / shrink;
|
||||||
|
} else if (inputImageType == sharp::ImageType::SVG ||
|
||||||
inputImageType == sharp::ImageType::PDF) {
|
inputImageType == sharp::ImageType::PDF) {
|
||||||
scale = 1.0 / shrink;
|
scale = 1.0 / shrink;
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
it('WebP shrink-on-load rounds to zero, ensure recalculation is correct', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(1080, 607)
|
.resize(1080, 607)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user