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

@@ -230,7 +230,8 @@ const Sharp = function (input, options) {
angle: 0,
rotationAngle: 0,
rotationBackground: [0, 0, 0, 255],
rotateBeforePreExtract: false,
rotateBefore: false,
orientBefore: false,
flip: false,
flop: false,
extendTop: 0,

View File

@@ -107,7 +107,7 @@ const mapFitToCanvas = {
* @private
*/
function isRotationExpected (options) {
return (options.angle % 360) !== 0 || options.input.autoOrient === true || options.rotationAngle !== 0;
return (options.angle % 360) !== 0 || options.rotationAngle !== 0;
}
/**
@@ -343,7 +343,7 @@ function resize (widthOrOptions, height, options) {
}
}
if (isRotationExpected(this.options) && isResizeExpected(this.options)) {
this.options.rotateBeforePreExtract = true;
this.options.rotateBefore = true;
}
return this;
}
@@ -490,9 +490,12 @@ function extract (options) {
// Ensure existing rotation occurs before pre-resize extraction
if (isRotationExpected(this.options) && !isResizeExpected(this.options)) {
if (this.options.widthPre === -1 || this.options.widthPost === -1) {
this.options.rotateBeforePreExtract = true;
this.options.rotateBefore = true;
}
}
if (this.options.input.autoOrient) {
this.options.orientBefore = true;
}
return this;
}
@@ -566,7 +569,7 @@ function trim (options) {
}
}
if (isRotationExpected(this.options)) {
this.options.rotateBeforePreExtract = true;
this.options.rotateBefore = true;
}
return this;
}