Skip to content

Commit

Permalink
Merge pull request #158 from nosecreek/master
Browse files Browse the repository at this point in the history
Always rotate images to ensure correct orientation
  • Loading branch information
zachleat authored Jan 15, 2024
2 parents 8cdf2f7 + 5575ce1 commit baea57d
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions img.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ class Image {
}

// https://jdhao.github.io/2019/07/31/image_rotation_exif_info/
// Orientation 5 to 8 means image is rotated (width/height are flipped)
// Orientation 5 to 8 means width/height are flipped
needsRotation(orientation) {
return orientation >= 5;
}
Expand Down Expand Up @@ -545,14 +545,10 @@ class Image {
if(metadata.format !== "svg" || !this.options.svgAllowUpscale) {
resizeOptions.withoutEnlargement = true;
}
if(this.needsRotation(metadata.orientation)) {
sharpInstance.rotate();
}
sharpInstance.rotate();
sharpInstance.resize(resizeOptions);
} else if (stat.width === metadata.width && metadata.format !== "svg") {
if(this.needsRotation(metadata.orientation)) {
sharpInstance.rotate();
}
} else if (metadata.format !== "svg") {
sharpInstance.rotate();
}

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

0 comments on commit baea57d

Please sign in to comment.