Rotation / Orientation of iphone HEIC files

Started by SebC, March 09, 2025, 05:27:00 PM

Previous topic - Next topic

SebC

Hello,

I used to have an iphone XR and I was able to do pretty much all I wanted on the EXIF metadata with Exiftool : changing date, rotation etc.

Now that I have upgraded to an iphone 16, I have problems with photo orientation.

With my old iphone XR's HEIC files, I only had to run a command such as "exiftool -rotation=0/90/180/270 IMG_xxxx.HEIC" and that instantly changed picture orientation. But with my iphone 16's HEIC files, this is not working anymore ... and worse, this just make that photo unreadable on my laptop.

I also tried to alter "orientation" tag with command such as "exiftool -orientation=1..8 -n IMG_xxxx.HEIC" but this seems to be useless.

Of course I can rotate the file on my iphone directly, but when you have multiple files, this is very convenient to rotate them all with a single command line on my laptop instead of one by one and multiple actions for each on my phone.

I don't know whether this is specific to iphone 16 or if it was the same with in between models, because I switched from XR to 16.

I asked the same question in Apple forum here : https://discussions.apple.com/thread/256000863?sortBy=rank
But as Matti Haveri suggested, the question is probably better located in Exiftool forum.

I'll attach 3 files (from inside Notre-Dame de Paris for those who are wondering ;) ) :
- IMG_6161.HEIC : original picture made on iphone 16 that I want to rotate
- IMG_E6161.HEIC : the same picture with 180° rotation made directly on the iphone (and of course this works)
- IMG_5588.HEIC : almost the same place but taken with my old iphone XR, and I can rotate this one with "exiftool -rotation=0/90/180/270"

As suggested by Matti on Apple forum thread, if I extract both orientation and rotation values with Exiftool, I get :
exiftool -a -G1 -s -Rotation -Orientation *
======== IMG_5588.HEIC << iphone XR pic that I can rotate without any issue
[QuickTime]     Rotation                        : Rotate 90 CW
[IFD0]          Orientation                     : Rotate 90 CW
======== IMG_6161.HEIC << iphone 16 pic that I can't rotate with Exiftool
[QuickTime]     Rotation                        : Rotate 90 CW
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Rotate 90 CW
======== IMG_E6161.HEIC << iphone 16 pic rotated directly on iphone 16
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Horizontal (normal)

There's a bit of inconsistency in IMG_6161.HEIC as there are 2 tags "Quicktime:Rotation" with different values. Note that the "iphone rotated" photo only has one.

Updating with Exiftool the values of IMG_6161.HEIC with what I have in IMG_E6161.HEIC does not help as the resulting IMG_6161.HEIC is unreadable :
exiftool -m -P -n -Rotation=0 -Orientation=1 IMG_6161.HEIC
exiftool -a -G1 -s -Rotation -Orientation IMG_6161.HEIC

[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Horizontal (normal)

Of course I'm using latest version of Exiftool.

I can't find any combination of rotation / orientation that can rotate iphone 16 HEIC files ... so, I'm hoping an Exiftool guru can help me.

Thanks a lot !
Sebastien

StarGeek

Quote from: SebC on March 09, 2025, 05:27:00 PMNow that I have upgraded to an iphone 16, I have problems with photo orientation.

With my old iphone XR's HEIC files, I only had to run a command such as "exiftool -rotation=0/90/180/270 IMG_xxxx.HEIC" and that instantly changed picture orientation. But with my iphone 16's HEIC files, this is not working anymore ... and worse, this just make that photo unreadable on my laptop.

Orientation on HEIC files is messy, because a lot of programs don't seem to read and respect the EXIF:Orientation tag. And the Rotation tag isn't really a tag in file, it's Composite tag that edits the QuickTime:MatrixStructure in a way that is understandable to humans. That is because HEIC files are based upon the MP4 format and look a lot like they are MP4 videos.

The fact that they become unreadable sounds like a very bad bug and Phil will have to take a look at the files to figure out what is wrong. (edit: Moved this thread to the Bug Report subforum)

QuoteI also tried to alter "orientation" tag with command such as "exiftool -orientation=1..8 -n IMG_xxxx.HEIC" but this seems to be useless.

The EXIF:Orientation is a tag that exiftool converts from numbers to a human-readable format. If you look at its entry on the EXIF Tags page, you will see a list of values that you would use to set it. The basic ones are
-Orientation=Horizontal
-Orientation="Rotate 90 CW"
-Orientation="Rotate 180"
-Orientation="Rotate 270 CW"

If you want to use the numbers, you have to include the -n (--printConv) option, usually by using the hashtag shortcut
-Orientation#=1
-Orientation#=6
-Orientation#=3
-Orientation#=8

QuoteI asked the same question in Apple forum here : https://discussions.apple.com/thread/256000863?sortBy=rank
But as Matti Haveri suggested, the question is probably better located in Exiftool forum.

Matti is on here as @wywh and is more experienced with the Apple environment than I am, so they might chime in here as well.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

StarGeek

I did a comparison of IMG_6161.HEIC and the edited version using the -v3 (-verbose3) option, and it looks like a lot of stuff is lost with the edit, though I'm not familiar enough with the inner workings to tell what is lost.

A comparison of the two outputs can be found here on DiffChecker, about 3,000 lines of output.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

#3
Hi Sebastien,

I see a definite problem in the way that ExifTool is handling these two different Rotation tags when trying to change them.  I'll see what I can do, but my MacOS system is too old to display HEIC images, so testing is tricky.  Check back here and I'll likely post some samples for you to test, probably tomorrow.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

Actually, I've quickly hacked each of the two rotation tags of your IMG_6161.HEIC separately to change them by 180 degrees.  Can you tell me which, if either, of these pictures displays properly:

IMG_6161a.HEIC

IMG_6161b.HEIC

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

wywh

Quote from: Phil Harvey on March 09, 2025, 09:18:17 PMwhich, if either, of these pictures displays properly
Both open OK in macOS 15.3.1 Sequoia Intel QuickLook and Preview.app in portrait mode, IMG_6161b.HEIC is correctly orientated, IMG_6161a.HEIC is upside down.

p.s. GraphicConverter 12.3.1 Browser displays IMG_6161b.HEIC OK, IMG_6161a.HEIC thumbnail is upside down and the main GC window briefly displays it upside down before displaying it correctly.

p.p.s. While testing otherwise OK iPhone 16 Pro .heic images I deliberately wrote different orientation to QuickTime:Rotation, IFD0:Orientation and XMP-tiff:Orientation to check what tag was preferred in some apps:

macOS Sequoia 15 QuickLook and Preview.app and Photoshop 2025 use the Rotation tag for the image display for .heic.

GraphicConverter Browser uses Rotation tag for .heic in its thumbnail display and very briefly in its main display before reverting using Orientation XMP-tiff:Orientation or preferably IFD0:Orientation tag if those differ.

In .jpg GC prefers IFD0:Orientation over XMP-tiff:Orientation if they differ. If there is only XMP-tiff:Orientation, then Browser thumbnails displays it and the main display displays it only briefly. I might nag GC author about this later.

wywh

I have a few iPhone 16 Pro iOS 18.2 .heic images and one of them that was shot in portrait mode has the same issue.

(I guess all rotations were done automatically inside the iPhone while shooting and no manual rotations were done. GraphicConverter might have created XMP-tiff:Orientation while editing other tags).

All landscape .heic have one Rotation tag but the portrait .heic has two:

exiftool -a -G1 -s -fileOrder5 FileName -Rotation -Orientation .
======== ./landscape.heic
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Horizontal (normal)
[XMP-tiff]      Orientation                     : Horizontal (normal)
======== ./portrait.heic
[QuickTime]     Rotation                        : Rotate 90 CW
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Rotate 90 CW
[XMP-tiff]      Orientation                     : Rotate 90 CW

Rotating works as expected in the landscape .heic but makes the portrait .heic unreadable in QuickLook, Preview.app, GraphicConverter and Photoshop 2025:

exiftool -Rotation='Rotate 270 CW' -Orientation='Rotate 270 CW' .

exiftool -a -G1 -s -fileOrder5 FileName -Rotation -Orientation .
======== ./landscape.heic
[QuickTime]     Rotation                        : Rotate 270 CW
[IFD0]          Orientation                     : Rotate 270 CW
[XMP-tiff]      Orientation                     : Rotate 270 CW
======== ./portrait.heic
[QuickTime]     Rotation                        : Rotate 270 CW
[IFD0]          Orientation                     : Rotate 270 CW
[XMP-tiff]      Orientation                     : Rotate 270 CW

- Matti

wywh

I did some more tests with those iPhone 16 Pro iOS 18.2 .heic images by rotating them in Apple's Sequoia apps.

-> Maybe there is an error how exiftool calculates Rotation tag? Unlike movies, .heic does not seem to have QuickTime:MatrixStructure tag.

Rotating 90° CCW via QuickLook initially seems to work for landscape, but the .heic is not really rotated so the next time QuickLook displays it is still in landscape anyway.

On the other hand, QuickLook successfully rotates 90° CCW the portrait .heic and in the process deletes the duplicate Rotation tag and XMP-tiff:Orientation. It is still readable in all apps:

exiftool -a -G1 -s -fileOrder5 FileName -Rotation -Orientation .
======== ./landscape.heic
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Horizontal (normal)
[XMP-tiff]      Orientation                     : Horizontal (normal)
======== ./portrait.heic
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Rotate 90 CW

But re-rotating in QuickLook does not always stick, and even if it sticks and orient differently in display, the tags exiftool displays are not changed and stay the same as above. Very weird.

Rotating 90° CCW in Preview.app succeeds for landscape and portrait but confusingly landscape tags stay the same although it is then displayed in portrait mode:

exiftool -a -G1 -s -fileOrder5 FileName -Rotation -Orientation .
======== ./landscape.heic
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Horizontal (normal)
======== ./portrait.heic
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Horizontal (normal)

Re-rotating 90° CCW in Preview.app makes both to display upside down as expected but the tags are still the same. Very confusing.

exiftool -a -G1 -s -fileOrder5 FileName -Rotation -Orientation .
======== ./landscape.heic
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Horizontal (normal)
======== ./portrait.heic
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Horizontal (normal)

- Matti

SebC

Hello all,

Quote from: Phil Harvey on March 09, 2025, 09:18:17 PMActually, I've quickly hacked each of the two rotation tags of your IMG_6161.HEIC separately to change them by 180 degrees.  Can you tell me which, if either, of these pictures displays properly:
IMG_6161a.HEIC
IMG_6161b.HEIC

- Phil

@Phil : as Matti said, both open fine, IMG_6161a.HEIC is upside down (so rotation was applied correctly) and IMG_6161b.HEIC is identical to the initial image IMG_6161.HEIC.


Quote from: wywh on March 10, 2025, 03:09:33 AMRotating works as expected in the landscape .heic but makes the portrait .heic unreadable in QuickLook, Preview.app, GraphicConverter and Photoshop 2025:

Oops, I was not expecting the behavior to change depending on the orientation of the original photo ... I can provide more sample pics in landscape format :
- IMG_6141.HEIC : iphone 16 landscape picture
- IMG_E6141.HEIC : iphone 16 landscape picture rotated 180° directly in the iphone
(sorry to ask, but how can I upload a file in an opened thread on Exiftool forum ?)

thanks,

wywh

Quote from: SebC on March 10, 2025, 06:11:21 AMhow can I upload a file in an opened thread on Exiftool forum ?
I guess you have to click the REPLY button, and then "Click and drag files here to attach them" under the reply dialog to do that. It seems the more readily available "Quick Reply" or replying via "Quoted text" does not allow attaching files.

SebC

Quote from: wywh on March 10, 2025, 06:37:48 AMIt seems the more readily available "Quick Reply" or replying via "Quoted text" does not allow attaching files.
Yes, indeed ... thanks for pointing out.

So here are the files.

Phil Harvey

OK.  I have a version that needs to be tested.  I wasn't sure what O/S everyone is using so I prepared a pre-release of all packages:

ExifTool-13.25p.pkg
Image-ExifTool-13.25p.tar.gz
exiftool-13.25p_64.zip
exiftool-13.25p_32.zip

Let me know how this works for writing Rotation to these HEIC images.

TIA for your help.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

SebC

Hello Phil,

I tested 13.25 and it is almost perfect, i.e. all commands "exiftool -rotation=nnn IMG_xxxx.HEIC" work like a charm (i.e. rotate photo and the output is readable), except when rotation angle is 0.

exiftool -rotation=90 IMG_6161.HEIC
    1 image files updated

exiftool -rotation=180 IMG_6161.HEIC
    1 image files updated

exiftool -rotation=270 IMG_6161.HEIC
    1 image files updated

exiftool -rotation=0 IMG_6161.HEIC
    0 image files updated
    1 image files unchanged

I've attached -v3 debug command outputs for rotation = 0 and 90.

wywh

13.25 (pre-release) works better but not perfectly. I try to explain:

I could set all those test landscape and portrait images correctly by the following commands. Also 'Rotate 270 CW', 'Rotate 180' and 'Rotate 90 CW' as well as the numeric commands work as expected.

-> But bringing Preview.app rotations to the mix puts this very confusingly out-of-sync, see below.

exiftool -m -P -overwrite_original -Rotation='Horizontal (normal)' -Orientation='Horizontal (normal)' landscape*

exiftool -m -P -overwrite_original -Rotation='Rotate 90 CW' -Orientation='Rotate 90 CW' portrait*

exiftool -a -G1 -s -fileOrder5 FileName -Rotation -Orientation .

======== ./landscape.heic
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Horizontal (normal)
[XMP-tiff]      Orientation                     : Horizontal (normal)
======== ./landscape_IMG_6141.HEIC
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Horizontal (normal)

======== ./portrait.heic
[QuickTime]     Rotation                        : Rotate 90 CW
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Rotate 90 CW
[XMP-tiff]      Orientation                     : Rotate 90 CW
======== ./portrait_IMG_5588.HEIC
[QuickTime]     Rotation                        : Rotate 90 CW
[IFD0]          Orientation                     : Rotate 90 CW
======== ./portrait_IMG_6161.HEIC
[QuickTime]     Rotation                        : Rotate 90 CW
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Rotate 90 CW

Only the images that were edited in the iPhone (marked by E) were incorrect:

======== ./landscape_IMG_E6141.HEIC <-<- upside down
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Horizontal (normal)

======== ./portrait_IMG_E6161.HEIC <-<- upside down 90° CCW
[QuickTime]     Rotation                        : Rotate 90 CW
[IFD0]          Orientation                     : Rotate 90 CW

I could not reset the to follow the rules via exiftool. But after I rotated them via Preview.app to their neutral position (landscape horizontal, portrait 90° CCW), then they followed exiftool rotations unless Preview broke the sync.

The following are my test images that were not previously manually rotated. I wonder why the portrait image has Rotation tag twice, maybe by design?

exiftool -a -G1 -s -fileOrder5 FileName -Rotation -Orientation .           
======== ./landscape.heic
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Horizontal (normal)
[XMP-tiff]      Orientation                     : Horizontal (normal)
======== ./portrait.heic
[QuickTime]     Rotation                        : Rotate 90 CW
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Rotate 90 CW
[XMP-tiff]      Orientation                     : Rotate 90 CW

If I use Apple's Preview.app to rotate both 90° CCW exiftool reads them as follows but no matter how many times I re-do the rotation to some another position exiftool still displays the following info despite all apps display the images rotated in various positions.

I can then apply rotation via exiftool but then the image position is out-of-sync until I fiddle with Preview rotations them to those neutral positions.

exiftool -a -G1 -s -fileOrder5 FileName -Rotation -Orientation .
======== ./landscape.heic
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Horizontal (normal)
======== ./portrait.heic
[QuickTime]     Rotation                        : Horizontal (Normal)
[IFD0]          Orientation                     : Horizontal (normal)

- Matti

wywh

As a side note this got me confused when testing. Starting point:

exiftool -a -G1 -s -n -Rotation -Orientation landscape.heic
[QuickTime]     Rotation                        : 3
[IFD0]          Orientation                     : 6
[XMP-tiff]      Orientation                     : 6

Then try to write numeric values. Despite forgetting to use -n it succeeds but writes wrong values without warnings:

exiftool -Rotation=0 -Orientation=1 landscape.heic   
    1 image files updated

exiftool -a -G1 -s -n -Rotation -Orientation landscape.heic
[QuickTime]     Rotation                        : 3
[IFD0]          Orientation                     : 3
[XMP-tiff]      Orientation                     : 3