ExifTool Forum

ExifTool => Bug Reports / Feature Requests => Topic started by: boustanihani on June 21, 2025, 06:43:50 AM

Title: Question / Feature Request: Autofix/Correct orientation
Post by: boustanihani on June 21, 2025, 06:43:50 AM
Question / Feature Request: Autofix/Correct orientation

Can we pass an argument to let Exiftool autocorrect/fix the Orientation a an image?
If not, please consider this as a feature request :)

This is what photoshop does when we simply open an image and overwrite it:

- If the JPG contains an EXIF orientation tag (common in photos from smartphones/cameras), Photoshop reads this tag and automatically rotates the image for display/editing.
- The image appears correctly oriented in Photoshop, even if the original pixel data is stored sideways or upside-down.
- When you save (using File > Save or Ctrl+S/Cmd+S), Photoshop saves the current visual state of the image (i.e., the rotated orientation).
- The EXIF orientation tag is removed (set to 1, meaning "no rotation needed") because the pixels are now permanently stored in the correct orientation.
- Result: The file is rewritten with fixed orientation, and the tag is stripped. Other software (browsers, viewers) will display it correctly without relying on EXIF.

Title: Re: Question / Feature Request: Autofix/Correct orientation
Post by: StarGeek on June 21, 2025, 10:22:08 AM
Exiftool only edits metadata. It cannot affect image data, which is what you are asking.

Additionally, what you are doing is a destructive recompress which deletes image data (see Reddit ELI5 (https://reddit.com/r/explainlikeimfive/comments/2ct3ax/eli5_what_does_the_phrase_needs_more_jpeg_mean/cjirqoi/?context=2), Know Your Meme (https://knowyourmeme.com/memes/needs-more-jpeg), and various More JPEG sites). This results in a "blockier" image with compression artifacts.

Example:
(https://i.kym-cdn.com/entries/icons/original/000/017/424/biMZme0OPzoHMrpF.png)

Instead of loading and re-saving, look for a program that does "JPEG Transforms". JPEGs can be losslessly rotated as long as the width/height is divisible by 8 or 16 (varies by JPEG). If you're on Windows, then Irfanview (https://www.irfanview.com/) with the "JPG_TRANSFORM" plugin can do this. XNView (https://www.xnview.com/en/) can also do JPEG transforms and is multi-platform.
Title: Re: Question / Feature Request: Autofix/Correct orientation
Post by: boustanihani on June 21, 2025, 03:49:45 PM
I need to automate this on a server. Do you possibly know a good node.js library for autorotation?
Title: Re: Question / Feature Request: Autofix/Correct orientation
Post by: StarGeek on June 21, 2025, 04:19:58 PM
I do not.

But all JPEG transform programs are based upon jpegtran (https://linux.die.net/man/1/jpegtran), and you might see if that's available on your server. jhead (https://www.sentex.net/%7Emwandel/jhead/) is a program that will use jpegtran to correctly rotate the images for you and is also available on some servers.
Title: Re: Question / Feature Request: Autofix/Correct orientation
Post by: boustanihani on June 21, 2025, 08:37:29 PM
jhead looks interesting, so if I do "jhead -autorot image.jpg" will the image get autorotated and will all metadata (EXIF, IPTC, XMP, etc.) remain preserved?
Title: Re: Question / Feature Request: Autofix/Correct orientation
Post by: StarGeek on June 21, 2025, 11:07:31 PM
According to the jhead source code (https://github.com/Matthias-Wandel/jhead/blob/db00efb27c7b358ec7dcd0c34f958cf775b175bd/jhead.c#L778), when it calls jpegtran, it uses the -copy all option, which will copy all the APP## jpeg blocks, which includes EXIF, IPTC, and XMP metadata, as well as other types.
Title: Re: Question / Feature Request: Autofix/Correct orientation
Post by: boustanihani on June 22, 2025, 05:47:07 AM
I ended up using: https://sharp.pixelplumbing.com/api-operation/#autoorient

await sharp(input).autoOrient().toFile(output);

And finally copying the metadata back to the autorotated file..