diff --git a/src/pipeline.cc b/src/pipeline.cc index a591f8c4..3c131634 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -184,7 +184,7 @@ class PipelineWorker : public Napi::AsyncWorker { if (inputImageType == sharp::ImageType::JPEG) { // Leave at least a factor of two for the final resize step, when fastShrinkOnLoad: false - // for more consistent results and avoid occasional small image shifting + // for more consistent results and to avoid extra sharpness to the image int factor = baton->fastShrinkOnLoad ? 1 : 2; if (shrink >= 8 * factor) { jpegShrinkOnLoad = 8; @@ -193,7 +193,7 @@ class PipelineWorker : public Napi::AsyncWorker { } else if (shrink >= 2 * factor) { jpegShrinkOnLoad = 2; } - // Skip shrink-on-load for known libjpeg rounding errors + // Lower shrink-on-load for known libjpeg rounding errors if (jpegShrinkOnLoad > 1 && static_cast(shrink) == jpegShrinkOnLoad) { jpegShrinkOnLoad /= 2; } diff --git a/test/fixtures/expected/fast-shrink-on-load-false.png b/test/fixtures/expected/fast-shrink-on-load-false.png deleted file mode 100644 index a4c7241d..00000000 Binary files a/test/fixtures/expected/fast-shrink-on-load-false.png and /dev/null differ diff --git a/test/fixtures/expected/fast-shrink-on-load-true.png b/test/fixtures/expected/fast-shrink-on-load.png similarity index 100% rename from test/fixtures/expected/fast-shrink-on-load-true.png rename to test/fixtures/expected/fast-shrink-on-load.png diff --git a/test/unit/resize.js b/test/unit/resize.js index b2777bfd..973113da 100644 --- a/test/unit/resize.js +++ b/test/unit/resize.js @@ -637,28 +637,21 @@ describe('Resize dimensions', function () { }); }); - it('fastShrinkOnLoad: false ensures image is not shifted', function (done) { - return sharp(fixtures.inputJpgCenteredImage) - .resize(9, 8, { fastShrinkOnLoad: false }) - .png() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(9, info.width); - assert.strictEqual(8, info.height); - fixtures.assertSimilar(fixtures.expected('fast-shrink-on-load-false.png'), data, done); - }); - }); - - it('fastShrinkOnLoad: true (default) might result in shifted image', function (done) { - return sharp(fixtures.inputJpgCenteredImage) - .resize(9, 8) - .png() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(9, info.width); - assert.strictEqual(8, info.height); - fixtures.assertSimilar(fixtures.expected('fast-shrink-on-load-true.png'), data, done); - }); + [ + true, + false + ].forEach(function (value) { + it(`fastShrinkOnLoad: ${value} does not causes image shifts`, function (done) { + sharp(fixtures.inputJpgCenteredImage) + .resize(9, 8, { fastShrinkOnLoad: value }) + .png() + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual(9, info.width); + assert.strictEqual(8, info.height); + fixtures.assertSimilar(fixtures.expected('fast-shrink-on-load.png'), data, done); + }); + }); }); [