-
-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle image rotation for JPEG output #227
Comments
Hello, libvips is currently fighting this issue too. See also #117 for previous battles with orientation. The situation seems to be that orientation is recorded in two places: as the set of transforms, and in EXIF. This means there are three cases:
The problem for us is that there seems to be no easy way to separate cases 2. and 3., so libvips doesn't know whether to strip the EXIF orientation or not. How about adding a little API so libheif users can tell if any load transforms were applied? It would save libheif having to add an EXIF parser as a dependency. |
Hi John, Actually, carrying out rotation based on EXIF according your case 2 is wrong with HEIF images. An API as you propose is not so simple, because in theory, HEIF transformations can be a chain of lots of different things. Rotate -> crop -> overlay with another image -> rotate back - > flip -> then put this into a grid with other images -> rotate the whole thing again -> ... |
Hi Dirk, thank you for replying so quickly. I'll remove our case 2 then, though I think that means some malformed images will not rotate correctly. I suppose I can at least blame someone else! |
Yes, blaming someone else for case 2 is the way to go :-) In fact, it's difficult to say how to correctly transform malformed images... |
The HEIF specification states that the EXIF orientation tag is only informational and should not be used to rotate the image. See strukturag/libheif#227 (comment)
The HEIF specification states that the EXIF orientation tag is only informational and should not be used to rotate the image. See strukturag/libheif#227 (comment)
My workaround was to use: After convert the image. |
To remove the orientation from the converted JPEG, I patched the It uses |
@farindk Can you share source which proves this?
I found the opposite information here: https://nokiatech.github.io/heif/technical.html#table-7
|
I was affected by this behavior today:
GIMP (and at least Dolphin in KDE Plasma) is able to interpret the orientation tag and asks me whether to rotate the image. Keeping the original in GIMP is the right choice. Dolphin doesn't ask; it always rotates. If anyone needs a "fix" that doesn't involve reprocessing the image, what I did was modify the EXIF information (using
|
My trick way:
then edit /usr/bin/heif-convert paste and save
|
I have noticed the same issue with converted files being rotated while the Exif value seems to be as per the original picture. I am having to add |
I have completely rewritten the orientation handling when converting from/to JPEG. |
Not needed anymore with updated heif-convert version.
Unfortunately, this test image is displayed with the wrong orientation using the latest release v1.15.2: The only solution for us is to use the old version v1.13.0. It seems to generate the same output JPEG, but does not reset the orientation, resulting in a correctly displayed image. |
@lastzero Hm I'm sure I already wrote an answer to this last week, but it's not here. Maybe I forgot to press 'send' ... I had a look at the There was a lot of confusion about this in the past and a lot of software was/is handling it incorrectly. The current behavior of libheif is correct. If you want to emulate the old (wrong) behavior, you have to get the orientation tag from the Exif and compare it with the transformations in the HEIF (libheif v1.16.1 can now output the transformation properties). If they disagree, you can apply the Exif rotation. But be warned: this is a wrong behavior. |
Thank you for your reply, @farindk! Inconsistent use of media metadata is a common phenomenon, unfortunately. We do our best to hide the complexity from our users, for example by automatically converting formats and normalizing data. However, since we don't have direct HEIC support in Go (which is why we very much appreciate your work), it's not clear to me how we can best work around the "wrong behavior":
|
I'm afraid there is no simple solution. When you say that
this is not actually true, since that version just made the same common errors. The current version (v1.16.0) handles it correctly. If you define "correct" as the orientation that the image is intended to be, you might have to take a look at other Exif metadata and determine from what software it was generated and maybe the generation timestamp and then from that modify the orientation in the hope that it will be correct and not make things worse. In my view, the best approach is to show images correctly according to the specification. If some of the images are then displayed wrong, there should be an easy way for the user to fix the file. This will put pressure on other software authors to write correct files. |
Thanks! I will check again. From what I remember, this mistake was made by Apple, which makes it difficult for small teams like ours to publicly blame them or successfully ask for improvements. Also, there appear to be many affected users and pictures, making it time consuming for us to provide support. I'm completely with you otherwise. |
You could check Exif for
I have no overview which iOS versions behave in which way. You probably have a larger data basis than me. |
Our archive of sample files is not exhaustive. Feel free to look around and use what seems helpful to you: I personally use Android and have very little time for HEIC in particular due to many other issues. If I learn more I will let you know! |
Image rotation is not working properly in all cases when outputting in JPEG format.
The problem is that is HEIF image is rotated, but the copied EXIF data causes the JPEG image to rotate again. Usually libheif disables HEIF image rotation when the output is JPEG and there is EXIF data, but with tiles images, this is not implemented. It is also a bit hacky anyways because when transformations are ignored, also other transformations (e.g. cropping) are not processed.
The right way to implement this would be to remove the
Orientation
tag from the output Exif data.The text was updated successfully, but these errors were encountered: