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.
This commit is contained in:
Don Denton 2024-12-08 19:51:41 -05:00
parent 7169a2555e
commit ab884e13cf
2 changed files with 26 additions and 0 deletions

View File

@ -58,6 +58,8 @@ function rotate (angle, options) {
if (this.options.angle || this.options.rotationAngle) {
this.options.debuglog('ignoring previous rotate options');
this.options.angle = 0;
this.options.rotationAngle = 0;
}
if (is.integer(angle) && !(angle % 90)) {
this.options.angle = angle;

View File

@ -447,6 +447,30 @@ describe('Rotation', function () {
assert.strictEqual(warningMessage, 'ignoring previous rotate options');
});
it('Multiple rotate: last one wins (cardinal)', function (done) {
sharp(fixtures.inputJpg)
.rotate(45)
.rotate(90)
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(2225, info.width);
assert.strictEqual(2725, info.height);
done();
});
});
it('Multiple rotate: last one wins (non cardinal)', function (done) {
sharp(fixtures.inputJpg)
.rotate(90)
.rotate(45)
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(3500, info.width);
assert.strictEqual(3500, info.height);
done();
});
});
it('Flip - vertical', function (done) {
sharp(fixtures.inputJpg)
.resize(320)