ExifTool Forum

General => Metadata => Topic started by: Henk Demper on October 03, 2022, 04:26:26 PM

Title: Rotation destroys Preview images and leaves invalid MPF marker section
Post by: Henk Demper on October 03, 2022, 04:26:26 PM
Hello Phil (I guess might answer),

I'm a developer having a large amount of JPEG photos and developing/improving an ultra-fast multi-platform (Mac, Windows, ...) viewing and manipulation application (private project, see in-progress snapshot) for (mainly) JPEG images in C++ using wxWidgets. I have created own code to parse the JPEG EXIF header and have used exiftool to analyse images and help out to decipher some of the encountered issues/details, thanks for all the good work on that ! For fast-displaying many images, I want to use the JPEG Thumbnail/Preview images (if present) first (which one based on current thumbnail viewing size), then revert to the (large) original image only if needed.

PhotoFlow.png

For years I have been rotating my images using jpegtran & jhead, because the older OS-ses (I just checked and on Windows that was in Explorer of Windows XP and 7) and browsers neglected the EXIF 'Orientation' tag. So I was under the assumption, and unaware of the specific JPEG/EXIF details at that time that I made a perfect (automated) rotation of any portrait image I made with one of my Nikon (D9 & 7200) cameras.

But now I see it a little different after recently tracing things back with exiftool, hex editors, own code and some Google searching. I believe this is more or less what happens:


So far so good and so I have a main image, a small thumbnail and 2 usable Preview images... but:


So effectively the main image is nicely rotated and the small, standard thumbnail is also rotated.
But I lost all my Preview images and the EXIF contains a bogus APP2 MPF Marker that I need to ignore.
This means that if I want to use Preview images for fast viewing (and assuming the standard marker is too small to be useful), I need to load the main image for all rotated JPEG files instead with the associated performance penalty. Maybe less of an issue on modern hardware, but even then the JPEG files are metadata invalid. If I would have known before I would never have rotated any image in the past. Now preview pages with large amount of (portrait) images will be less snappy to load.

My believe/advice would be to not rotate any JPEG image with jpegtran/jhead/.... It is a bad thing, unless you are not concerned about Preview images and/or correct metadata. This is certainly not a big issue nowadays while most viewers respect the Orientation tag in the EXIF.

The question at the end (and assuring that I follow the correct coding path now): would you agree with above text: what is happening and the consequences ? Any additional, related information is appreciated.

Thanks in advance,

Best regards,

Henk Demper
Title: Re: Rotation destroys Preview images and leaves invalid MPF marker section
Post by: Phil Harvey on October 03, 2022, 08:37:10 PM
Henk,

I think you are correct, but I have a question:

Why do you rotate the image and change the Orientation tag.  Just changing the Orientation tag should have the effect of rotating the main image.  Of course, rotation of the thumbnails and preview is another issue, but other than this, why doesn't just changing the Orientation do what you want?

- Phil

I see.  You explained that you want compatibility with older browsers. (I scanned over that, TLDR)
Title: Re: Rotation destroys Preview images and leaves invalid MPF marker section
Post by: Henk Demper on October 04, 2022, 10:45:53 AM
Hi Phil,

Thanks for the reply.

Indeed I started rotating 'back then' because of compatibility with older OS-ses (Explorer)/browsers. I kept doing this till date because I assumed it was not harmful and only made the files better, and it saved me implementing using the Orientation tag in my older version of the photo handling application...

From now on I will not rotate any more and exclusively (in existing & own apps) rely on the Orientation setting.

PS: Mentioned Nikon D9 in previous message, that should be Nikon D90...

Thanks again,

Henk Demper
Title: Re: Rotation destroys Preview images and leaves invalid MPF marker section
Post by: blue-j on October 15, 2022, 06:42:12 PM
exiftran is an alternative to jpegtran that is also lossless but includes editing the EXIF orientation tag and thumbnails, should you decide to want that.

https://linux.die.net/man/1/exiftran

Quoteexiftran is a command line utility to transform digital camera JPEG images. It can do lossless rotations like jpegtran, but unlike jpegtran it can process multiple images at once, and it cares about the Exif data: it can rotate images automatically by checking the Exif orientation tag, it updates the Exif information (image dimensions/orientation) if needed, and it also rotates the Exif thumbnail.

I believe it may be Linux only, but am unsure, so perhaps not usable for you.

- J