diff --git a/src/pipeline.cc b/src/pipeline.cc index d26dbf4a..29bce040 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -291,8 +291,8 @@ class PipelineWorker : public Nan::AsyncWorker { if (xshrink > 1 && yshrink > 1 && (xresidual == 1.0 || yresidual == 1.0)) { xshrink = xshrink / 2; yshrink = yshrink / 2; - xresidual = xresidual / 2.0; - yresidual = yresidual / 2.0; + xresidual = static_cast(xshrink) / xfactor; + yresidual = static_cast(yshrink) / yfactor; } // Ensure we're using a device-independent colour space diff --git a/test/fixtures/expected/resize-diff-shrink-even.jpg b/test/fixtures/expected/resize-diff-shrink-even.jpg new file mode 100644 index 00000000..a00853c7 Binary files /dev/null and b/test/fixtures/expected/resize-diff-shrink-even.jpg differ diff --git a/test/fixtures/expected/resize-diff-shrink-odd.jpg b/test/fixtures/expected/resize-diff-shrink-odd.jpg new file mode 100644 index 00000000..f2f6c570 Binary files /dev/null and b/test/fixtures/expected/resize-diff-shrink-odd.jpg differ diff --git a/test/unit/resize.js b/test/unit/resize.js index 4664be78..47958dad 100644 --- a/test/unit/resize.js +++ b/test/unit/resize.js @@ -413,14 +413,39 @@ describe('Resize dimensions', function () { }); }); - it('Dimensions that result in differing shrinks on each axis', function () { - return sharp(fixtures.inputJpg) + it('Dimensions that result in differing even shrinks on each axis', function (done) { + sharp(fixtures.inputJpg) .resize(645, 399) - .toBuffer() - .then(function (data) { - return sharp(data) + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual(645, info.width); + assert.strictEqual(399, info.height); + sharp(data) .resize(150, 100) - .toBuffer(); + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual(150, info.width); + assert.strictEqual(100, info.height); + fixtures.assertSimilar(fixtures.expected('resize-diff-shrink-even.jpg'), data, done); + }); + }); + }); + + it('Dimensions that result in differing odd shrinks on each axis', function (done) { + return sharp(fixtures.inputJpg) + .resize(600, 399) + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual(600, info.width); + assert.strictEqual(399, info.height); + sharp(data) + .resize(200) + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual(200, info.width); + assert.strictEqual(133, info.height); + fixtures.assertSimilar(fixtures.expected('resize-diff-shrink-odd.jpg'), data, done); + }); }); }); });