diff --git a/src/pipeline.cc b/src/pipeline.cc index 4396f563..972df00f 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -220,12 +220,12 @@ class PipelineWorker : public Nan::AsyncWorker { } // If integral x and y shrink are equal, try to use shrink-on-load for JPEG and WebP, - // but not when applying gamma correction or pre-resize extract + // but not when applying gamma correction, pre-resize extract or trim int shrink_on_load = 1; if ( xshrink == yshrink && xshrink >= 2 && (inputImageType == ImageType::JPEG || inputImageType == ImageType::WEBP) && - baton->gamma == 0 && baton->topOffsetPre == -1 + baton->gamma == 0 && baton->topOffsetPre == -1 && baton->trimTolerance == 0 ) { if (xshrink >= 8) { xfactor = xfactor / 8; diff --git a/test/fixtures/alpha-layer-2-ink.jpg b/test/fixtures/alpha-layer-2-ink.jpg new file mode 100644 index 00000000..ca96a1af Binary files /dev/null and b/test/fixtures/alpha-layer-2-ink.jpg differ diff --git a/test/fixtures/expected/alpha-layer-2-trim-resize.jpg b/test/fixtures/expected/alpha-layer-2-trim-resize.jpg new file mode 100644 index 00000000..aaa548a7 Binary files /dev/null and b/test/fixtures/expected/alpha-layer-2-trim-resize.jpg differ diff --git a/test/fixtures/index.js b/test/fixtures/index.js index d45d8a97..2876fd87 100644 --- a/test/fixtures/index.js +++ b/test/fixtures/index.js @@ -65,6 +65,7 @@ module.exports = { inputJpgWithLowContrast: getPath('low-contrast.jpg'), // http://www.flickr.com/photos/grizdave/2569067123/ inputJpgLarge: getPath('giant-image.jpg'), inputJpg320x240: getPath('320x240.jpg'), // http://www.andrewault.net/2010/01/26/create-a-test-pattern-video-with-perl/ + inputJpgOverlayLayer2: getPath('alpha-layer-2-ink.jpg'), inputPng: getPath('50020484-00001.png'), // http://c.searspartsdirect.com/lis_png/PLDM/50020484-00001.png inputPngWithTransparency: getPath('blackbug.png'), // public domain diff --git a/test/unit/trim.js b/test/unit/trim.js index d18247f8..3be3fb7c 100644 --- a/test/unit/trim.js +++ b/test/unit/trim.js @@ -20,6 +20,20 @@ describe('Trim borders', function () { }); }); + it('Skip shrink-on-load', function (done) { + const expected = fixtures.expected('alpha-layer-2-trim-resize.jpg'); + sharp(fixtures.inputJpgOverlayLayer2) + .trim() + .resize(300) + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual('jpeg', info.format); + assert.strictEqual(300, info.width); + assert.strictEqual(300, info.height); + fixtures.assertSimilar(expected, data, done); + }); + }); + it('16-bit PNG with alpha channel', function (done) { sharp(fixtures.inputPngWithTransparency16bit) .resize(32, 32)