Ensure autoOrient occurs before non-90 rotation #4425

- Separate orient vs rotate ordering logic
- Simplify EXIF auto-orient by using only rotate and/or flop
This commit is contained in:
Lovell Fuller
2025-07-21 16:10:34 +01:00
parent 67462bee79
commit 08b4242efe
6 changed files with 74 additions and 53 deletions

View File

@@ -565,9 +565,9 @@ describe('Rotation', function () {
.raw()
.toBuffer();
assert.strictEqual(r, 60);
assert.strictEqual(g, 73);
assert.strictEqual(b, 52);
assert.strictEqual(r, 61);
assert.strictEqual(g, 74);
assert.strictEqual(b, 51);
});
it('Flip and rotate ordering', async () => {
@@ -648,6 +648,27 @@ describe('Rotation', function () {
assert.strictEqual(orientation, undefined);
});
it('Auto-orient and rotate 45', async () => {
const data = await sharp(fixtures.inputJpgWithLandscapeExif2, { autoOrient: true })
.rotate(45)
.toBuffer();
const { width, height } = await sharp(data).metadata();
assert.strictEqual(width, 742);
assert.strictEqual(height, 742);
});
it('Auto-orient, extract and rotate 45', async () => {
const data = await sharp(fixtures.inputJpgWithLandscapeExif2, { autoOrient: true })
.extract({ left: 20, top: 20, width: 200, height: 100 })
.rotate(45)
.toBuffer();
const { width, height } = await sharp(data).metadata();
assert.strictEqual(width, 212);
assert.strictEqual(height, 212);
});
it('Invalid autoOrient throws', () =>
assert.throws(
() => sharp({ autoOrient: 'fail' }),