diff --git a/docs/changelog.md b/docs/changelog.md index 09ea8ec4..12b1b216 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -26,6 +26,10 @@ [#367](https://github.com/lovell/sharp/issues/367) [@salzhrani](https://github.com/salzhrani) +* Ensure ratios are not swapped when rotating 90/270 and ignoring aspect. + [#387](https://github.com/lovell/sharp/issues/387) + [@kleisauke](https://github.com/kleisauke) + ### v0.13 - "*mind*" #### v0.13.1 - 27th February 2016 diff --git a/src/pipeline.cc b/src/pipeline.cc index 41a992c0..87225bda 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -194,7 +194,8 @@ class PipelineWorker : public AsyncWorker { // Get pre-resize image width and height int inputWidth = image.width(); int inputHeight = image.height(); - if (!baton->rotateBeforePreExtract && (rotation == VIPS_ANGLE_D90 || rotation == VIPS_ANGLE_D270)) { + if (baton->canvas != Canvas::IGNORE_ASPECT && !baton->rotateBeforePreExtract && + (rotation == VIPS_ANGLE_D90 || rotation == VIPS_ANGLE_D270)) { // Swap input output width and height when rotating by 90 or 270 degrees std::swap(inputWidth, inputHeight); } @@ -392,7 +393,8 @@ class PipelineWorker : public AsyncWorker { // Recalculate residual float based on dimensions of required vs shrunk images int shrunkWidth = image.width(); int shrunkHeight = image.height(); - if (rotation == VIPS_ANGLE_D90 || rotation == VIPS_ANGLE_D270) { + if (baton->canvas != Canvas::IGNORE_ASPECT && !baton->rotateBeforePreExtract && + (rotation == VIPS_ANGLE_D90 || rotation == VIPS_ANGLE_D270)) { // Swap input output width and height when rotating by 90 or 270 degrees std::swap(shrunkWidth, shrunkHeight); } diff --git a/test/unit/rotate.js b/test/unit/rotate.js index a7eac21d..02fa6f53 100644 --- a/test/unit/rotate.js +++ b/test/unit/rotate.js @@ -35,6 +35,23 @@ describe('Rotation', function() { }); }); + it('Rotate by 270 degrees, square output ignoring aspect ratio', function(done) { + sharp(fixtures.inputJpg) + .resize(240, 240) + .ignoreAspectRatio() + .rotate(270) + .toBuffer(function(err, data, info) { + if (err) throw err; + assert.strictEqual(240, info.width); + assert.strictEqual(240, info.height); + sharp(data).metadata(function(err, metadata) { + assert.strictEqual(240, metadata.width); + assert.strictEqual(240, metadata.height); + done(); + }); + }); + }); + it('Input image has Orientation EXIF tag but do not rotate output', function(done) { sharp(fixtures.inputJpgWithExif) .resize(320)