mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Ensure correct ordering of rotate-then-trim ops #2087
This commit is contained in:
@@ -85,6 +85,13 @@ const mapFitToCanvas = {
|
||||
outside: 'min'
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function isRotationExpected (options) {
|
||||
return (options.angle % 360) !== 0 || options.useExifOrientation === true || options.rotationAngle !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize image to `width`, `height` or `width x height`.
|
||||
*
|
||||
@@ -367,7 +374,7 @@ function extract (options) {
|
||||
}
|
||||
}, this);
|
||||
// Ensure existing rotation occurs before pre-resize extraction
|
||||
if (suffix === 'Pre' && ((this.options.angle % 360) !== 0 || this.options.useExifOrientation === true || this.options.rotationAngle !== 0)) {
|
||||
if (suffix === 'Pre' && isRotationExpected(this.options)) {
|
||||
this.options.rotateBeforePreExtract = true;
|
||||
}
|
||||
return this;
|
||||
@@ -391,6 +398,9 @@ function trim (threshold) {
|
||||
} else {
|
||||
throw is.invalidParameterError('threshold', 'number greater than zero', threshold);
|
||||
}
|
||||
if (this.options.trimThreshold && isRotationExpected(this.options)) {
|
||||
this.options.rotateBeforePreExtract = true;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user