diff --git a/docs/changelog.md b/docs/changelog.md index 93209952..9222f720 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -10,6 +10,10 @@ Requires libvips v8.5.5. [#828](https://github.com/lovell/sharp/pull/828) [@YvesBos](https://github.com/YvesBos) +* Ensure flip and flop operations work with auto-rotate. + [#837](https://github.com/lovell/sharp/issues/837) + [@rexxars](https://github.com/rexxars) + #### v0.18.1 - 30th May 2017 * Remove regression from #781 that could cause incorrect shrink calculation. diff --git a/src/pipeline.cc b/src/pipeline.cc index 6dd8cbee..4396f563 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -83,8 +83,11 @@ class PipelineWorker : public Nan::AsyncWorker { VipsAngle rotation; if (baton->useExifOrientation) { // Rotate and flip image according to Exif orientation - // (ignore the requested rotation and flip) - std::tie(rotation, baton->flip, baton->flop) = CalculateExifRotationAndFlip(sharp::ExifOrientation(image)); + bool flip; + bool flop; + std::tie(rotation, flip, flop) = CalculateExifRotationAndFlip(sharp::ExifOrientation(image)); + baton->flip = baton->flip || flip; + baton->flop = baton->flop || flop; } else { rotation = CalculateAngleRotation(baton->angle); } diff --git a/test/fixtures/expected/rotate-and-flip.jpg b/test/fixtures/expected/rotate-and-flip.jpg new file mode 100644 index 00000000..b7668131 Binary files /dev/null and b/test/fixtures/expected/rotate-and-flip.jpg differ diff --git a/test/fixtures/expected/rotate-and-flop.jpg b/test/fixtures/expected/rotate-and-flop.jpg new file mode 100644 index 00000000..bad159ed Binary files /dev/null and b/test/fixtures/expected/rotate-and-flop.jpg differ diff --git a/test/unit/rotate.js b/test/unit/rotate.js index f3f38a75..6ddc9587 100644 --- a/test/unit/rotate.js +++ b/test/unit/rotate.js @@ -253,4 +253,32 @@ describe('Rotation', function () { fixtures.assertSimilar(fixtures.inputJpg, data, done); }); }); + + it('Auto-rotate and flip', function (done) { + sharp(fixtures.inputJpgWithExif) + .rotate() + .flip() + .resize(320) + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual('jpeg', info.format); + assert.strictEqual(320, info.width); + assert.strictEqual(240, info.height); + fixtures.assertSimilar(fixtures.expected('rotate-and-flip.jpg'), data, done); + }); + }); + + it('Auto-rotate and flop', function (done) { + sharp(fixtures.inputJpgWithExif) + .rotate() + .flop() + .resize(320) + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual('jpeg', info.format); + assert.strictEqual(320, info.width); + assert.strictEqual(240, info.height); + fixtures.assertSimilar(fixtures.expected('rotate-and-flop.jpg'), data, done); + }); + }); });