Skip to content

Commit

Permalink
Add further test case for #387, which builds on 25b63a2
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Mar 30, 2016
1 parent 25b63a2 commit 24fb0c3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@
"dependencies": {
"bluebird": "^3.3.4",
"color": "^0.11.1",
"nan": "^2.2.0",
"nan": "^2.2.1",
"semver": "^5.1.0",
"request": "^2.69.0",
"tar": "^2.2.1"
},
"devDependencies": {
"async": "^1.5.2",
"coveralls": "^2.11.8",
"coveralls": "^2.11.9",
"exif-reader": "^1.0.0",
"icc": "^0.0.2",
"istanbul": "^0.4.2",
Expand Down
16 changes: 12 additions & 4 deletions src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class PipelineWorker : public AsyncWorker {
// Get pre-resize image width and height
int inputWidth = image.width();
int inputHeight = image.height();
if (baton->canvas != Canvas::IGNORE_ASPECT && !baton->rotateBeforePreExtract &&
if (!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);
Expand Down Expand Up @@ -239,7 +239,10 @@ class PipelineWorker : public AsyncWorker {
}
break;
case Canvas::IGNORE_ASPECT:
// xfactor, yfactor OK!
if (!baton->rotateBeforePreExtract &&
(rotation == VIPS_ANGLE_D90 || rotation == VIPS_ANGLE_D270)) {
std::swap(xfactor, yfactor);
}
break;
}
} else if (baton->width > 0) {
Expand Down Expand Up @@ -393,7 +396,7 @@ class PipelineWorker : public AsyncWorker {
// Recalculate residual float based on dimensions of required vs shrunk images
int shrunkWidth = image.width();
int shrunkHeight = image.height();
if (baton->canvas != Canvas::IGNORE_ASPECT && !baton->rotateBeforePreExtract &&
if (!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);
Expand All @@ -403,7 +406,12 @@ class PipelineWorker : public AsyncWorker {
if (baton->canvas == Canvas::EMBED) {
xresidual = std::min(xresidual, yresidual);
yresidual = xresidual;
} else if (baton->canvas != Canvas::IGNORE_ASPECT) {
} else if (baton->canvas == Canvas::IGNORE_ASPECT) {
if (!baton->rotateBeforePreExtract &&
(rotation == VIPS_ANGLE_D90 || rotation == VIPS_ANGLE_D270)) {
std::swap(xresidual, yresidual);
}
} else {
xresidual = std::max(xresidual, yresidual);
yresidual = xresidual;
}
Expand Down
19 changes: 18 additions & 1 deletion test/unit/rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,24 @@ describe('Rotation', function() {
assert.strictEqual(240, metadata.height);
done();
});
});
});
});

it('Rotate by 270 degrees, rectangular output ignoring aspect ratio', function(done) {
sharp(fixtures.inputJpg)
.resize(320, 240)
.ignoreAspectRatio()
.rotate(270)
.toBuffer(function(err, data, info) {
if (err) throw err;
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
sharp(data).metadata(function(err, metadata) {
assert.strictEqual(320, metadata.width);
assert.strictEqual(240, metadata.height);
done();
});
});
});

it('Input image has Orientation EXIF tag but do not rotate output', function(done) {
Expand Down

0 comments on commit 24fb0c3

Please sign in to comment.