Skip to content

Commit ab884e1

Browse files
Fix double rotate behavior
Docs and warnings state that we ignore previous calls to `.rotate()` when multiple calls are made, but we were not correctly resetting the state at the start of the second call.
1 parent 7169a25 commit ab884e1

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/operation.js

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ function rotate (angle, options) {
5858

5959
if (this.options.angle || this.options.rotationAngle) {
6060
this.options.debuglog('ignoring previous rotate options');
61+
this.options.angle = 0;
62+
this.options.rotationAngle = 0;
6163
}
6264
if (is.integer(angle) && !(angle % 90)) {
6365
this.options.angle = angle;

test/unit/rotate.js

+24
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,30 @@ describe('Rotation', function () {
447447
assert.strictEqual(warningMessage, 'ignoring previous rotate options');
448448
});
449449

450+
it('Multiple rotate: last one wins (cardinal)', function (done) {
451+
sharp(fixtures.inputJpg)
452+
.rotate(45)
453+
.rotate(90)
454+
.toBuffer(function (err, data, info) {
455+
if (err) throw err;
456+
assert.strictEqual(2225, info.width);
457+
assert.strictEqual(2725, info.height);
458+
done();
459+
});
460+
});
461+
462+
it('Multiple rotate: last one wins (non cardinal)', function (done) {
463+
sharp(fixtures.inputJpg)
464+
.rotate(90)
465+
.rotate(45)
466+
.toBuffer(function (err, data, info) {
467+
if (err) throw err;
468+
assert.strictEqual(3500, info.width);
469+
assert.strictEqual(3500, info.height);
470+
done();
471+
});
472+
});
473+
450474
it('Flip - vertical', function (done) {
451475
sharp(fixtures.inputJpg)
452476
.resize(320)

0 commit comments

Comments
 (0)