diff --git a/docs/changelog.md b/docs/changelog.md index f518a8bb..7115a478 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,11 @@ Requires libvips v8.10.6 +### v0.28.2 - TBD + +* Skip shrink-on-load where one dimension <4px. + [#2653](https://github.com/lovell/sharp/issues/2653) + ### v0.28.1 - 5th April 2021 * Ensure all installation errors are logged with a more obvious prefix. diff --git a/src/pipeline.cc b/src/pipeline.cc index 7683cc07..30c334c1 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -226,7 +226,8 @@ class PipelineWorker : public Napi::AsyncWorker { if ( xshrink == yshrink && xshrink >= 2 * shrink_on_load_factor && (inputImageType == sharp::ImageType::JPEG || inputImageType == sharp::ImageType::WEBP) && - baton->gamma == 0 && baton->topOffsetPre == -1 && baton->trimThreshold == 0.0 + baton->gamma == 0 && baton->topOffsetPre == -1 && baton->trimThreshold == 0.0 && + image.width() > 3 && image.height() > 3 ) { if (xshrink >= 8 * shrink_on_load_factor) { xfactor = xfactor / 8; diff --git a/test/unit/resize.js b/test/unit/resize.js index a293fca4..01c92805 100644 --- a/test/unit/resize.js +++ b/test/unit/resize.js @@ -605,6 +605,26 @@ describe('Resize dimensions', function () { }); }); + it('Skip shrink-on-load where one dimension <4px', async () => { + const jpeg = await sharp({ + create: { + width: 100, + height: 3, + channels: 3, + background: 'red' + } + }) + .jpeg() + .toBuffer(); + + const { info } = await sharp(jpeg) + .resize(8) + .toBuffer({ resolveWithObject: true }); + + assert.strictEqual(info.width, 8); + assert.strictEqual(info.height, 1); + }); + it('unknown kernel throws', function () { assert.throws(function () { sharp().resize(null, null, { kernel: 'unknown' });