Skip to content

Commit

Permalink
Adds fixOrientation option for opt-in on #158
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jan 15, 2024
1 parent baea57d commit 05130ff
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions img.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ const globalOptions = {

hashLength: 10, // Truncates the hash to this length

fixOrientation: false, // always rotate images to ensure correct orientation

// Advanced
useCacheValidityInHash: true,

};

const MIME_TYPES = {
Expand Down Expand Up @@ -545,10 +548,14 @@ class Image {
if(metadata.format !== "svg" || !this.options.svgAllowUpscale) {
resizeOptions.withoutEnlargement = true;
}
sharpInstance.rotate();
if(this.options.fixOrientation || this.needsRotation(metadata.orientation)) {
sharpInstance.rotate();
}
sharpInstance.resize(resizeOptions);
} else if (metadata.format !== "svg") {
sharpInstance.rotate();
if(this.options.fixOrientation || stat.width === metadata.width && this.needsRotation(metadata.orientation)) {
sharpInstance.rotate();
}
}

if(!this.options.dryRun) {
Expand Down

0 comments on commit 05130ff

Please sign in to comment.