Python pillow-heif not retrieving exif data from HEIC photo

286 views Asked by At

I have been pulling my hair out trying to gather exif data from HEIC photos on windows. Pyheif is not supported on windows, and I need a solution that will also work on MacOs. Efficiency is important as well, I do not want to have to convert the images to jpg, but will try that as a last resort. I have tried pillow-heif, and it is not opening the photos in way where the exif data is accessible.

Below is the code I am using.

    def get_exif_data_pillow(file, folder_path):
        """Retrieve EXIF data from an image using Pillow's _getexif method."""
        register_heif_opener()
        try:
            with Image.open(os.path.join(folder_path, file)) as img:
                return img._getexif()
        except Exception as e:
            print(e)

From what I can see when debugging pycharm, 'img' is registered as:

<pillow_heif.as_plugin.HeifImageFile image mode=RGB size=3024x4032 at 0x22DEC75A610>

so it is opening the file. However upon inspection, it does not have any exif data. The photos I am using have loads of exif data so this does not make sense to me. Furthermore, img._getexif() returns a mysterious index out of range error, probably from trying to access the non-existant exif data.

Is there anything I can do here to save this? This would be the most elegant and simple solution - if it worked.

0

There are 0 answers