kivy / plyer

Plyer is a platform-independent Python wrapper for platform-dependent APIs
https://plyer.readthedocs.io
MIT License
1.61k stars 427 forks source link

filechooser.open_file should retain EXIF data when opening images in iOS #766

Closed kschepps closed 1 year ago

kschepps commented 1 year ago

I'm building an app that needs to select an image. The images displayed in Plyer Filechooser are showing in the correct orientation, but once an image is selected it does not retain the correct orientation.

For Android, it's not an issue. I'm not using Filechooser for Android, but I can grab the EXIF info and re-orient the image using the code below. However, this code does not work in iOS when using Filechooser. It seems like Filechooser is creating a copy of the file into the App's directory, but that file does not contain EXIF data. Therefor, I can't rotate the image correctly. This code always fails inside the try expression.

`

from PIL import Image as PilImage, ExifTags
dst = 'path/to/image'
try:
    pil_img = PilImage.open(dst)
    for orientation in ExifTags.TAGS.keys():
        if ExifTags.TAGS[orientation]=='Orientation':
            break

    exif = pil_img._getexif()

    if exif is not None:
        if exif[orientation] == 3:
            pil_img=pil_img.rotate(180, expand=True)
        elif exif[orientation] == 6:
            pil_img=pil_img.rotate(270, expand=True)
        elif exif[orientation] == 8:
            pil_img=pil_img.rotate(90, expand=True)

    pil_img.save(dst)
except: pass

`

kschepps commented 1 year ago

This might be related to this issue https://github.com/kivy/kivy-ios/issues/787

I'm having issues using Pillow after deleting libfreetype as a workaround to this issue building the code. I didn't realize until just now.