Skip to content
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

On Mac, rotating image in Finder does not result in rotated image after loading #468

Open
coinbump opened this issue Sep 7, 2024 · 8 comments

Comments

@coinbump
Copy link

coinbump commented Sep 7, 2024

Here's the code:

SDL_Surface* surface = IMG_Load(path.string().c_str());

This works usually, but if I use the Mac Finder to rotate an image (command-L), the image appears rotated in the Finder, but loads with the original orientation in SDLImage.

I suspect this is some kind of optimization in MacOS to make rotation a change in metadata instead of actually rotating the image pixels to save time, but I'm not sure.

@slouken
Copy link
Collaborator

slouken commented Sep 7, 2024

Can you attach a link to a rotated image?

@coinbump
Copy link
Author

coinbump commented Sep 9, 2024

heart-full

Here is a simple pixel heart. It was originally oriented like a normal heart. Then I rotated it in the Finder. Photoshop opens it as rotated, but SDLImage does not. Hopefully uploading to GitHub here doesn't change it.

@coinbump
Copy link
Author

coinbump commented Sep 9, 2024

heart-full.png.zip

Just in case uploading alters the image somehow, here it is compressed.

@madebr
Copy link
Contributor

madebr commented Sep 9, 2024

What happens if you remove the __MACOSX folder next to the image?

@coinbump
Copy link
Author

coinbump commented Sep 9, 2024

I don't see a __MACOSX folder, that might just be added when you zip it.

Interestingly the image appears rotated in both Finder and Photoshop, but non-rotated in the GitHub app.

So this may be some edge case that Adobe optimized for since they're Mac friendly.

Screenshot 2024-09-09 at 6 23 55 AM

@coinbump
Copy link
Author

coinbump commented Sep 9, 2024

Screenshot 2024-09-09 at 6 31 50 AM

Ok, I figured it out. I opened the png in an app that shows the png metadata.

And the rotated image has an Orientation property that non-rotated pngs do not.

So I guess it would be up to SDLImage to rotate the png? Or maybe at least send us the metadata for orientation so we can do it ourselves.

@madebr
Copy link
Contributor

madebr commented Sep 9, 2024

gimp and gnome's image viewer also show the image as non-rotated.

I opened the file in imhex, and see an embedded iTXT chunk with a ML:com.adobe.xmp key, containing:

<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 6.0.0">
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Description rdf:about=""
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:xmp="http://ns.adobe.com/xap/1.0/"
    xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
    xmlns:stEvt="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#"
    xmlns:tiff="http://ns.adobe.com/tiff/1.0/"
    xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"
   dc:format="image/png"
   xmp:CreatorTool="Adobe Photoshop 24.4 (Macintosh)"
   xmp:ModifyDate="2023-05-09T19:32:18-07:00"
   xmp:CreateDate="2022-11-16T19:14:27-08:00"
   xmp:MetadataDate="2023-05-09T19:32:18-07:00"
   xmpMM:OriginalDocumentID="xmp.did:9d46c96f-0c34-4c07-a596-61726ed10945"
   xmpMM:DocumentID="xmp.did:9d46c96f-0c34-4c07-a596-61726ed10945"
   xmpMM:InstanceID="xmp.iid:9d46c96f-0c34-4c07-a596-61726ed10945"
   tiff:Orientation="8"
   photoshop:ColorMode="3">
   <xmpMM:History>
    <rdf:Seq>
     <rdf:li
      stEvt:softwareAgent="Adobe Photoshop 24.4 (Macintosh)"
      stEvt:when="2022-11-16T19:14:27-08:00"
      stEvt:instanceID="xmp.iid:9d46c96f-0c34-4c07-a596-61726ed10945"
      stEvt:action="created"/>
    </rdf:Seq>
   </xmpMM:History>
  </rdf:Description>
 </rdf:RDF>
</x:xmpmeta>
<?xpacket end="r"?>

SDL_image does not have a xml parser.

@coinbump
Copy link
Author

coinbump commented Sep 9, 2024

I would say, if it's difficult to fix, maybe just document it somewhere. Because it is confusing for Mac users.

Not the end of the world, since we can rotate with other apps than the Finder, just less convenient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants