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

HEIC support #105

Closed
unmade opened this issue Oct 28, 2022 · 10 comments · Fixed by #107
Closed

HEIC support #105

unmade opened this issue Oct 28, 2022 · 10 comments · Fixed by #107

Comments

@unmade
Copy link
Owner

unmade commented Oct 28, 2022

No description provided.

@bigcat88
Copy link

from pillow_heif import HeifImagePlugin

that's all.

@unmade
Copy link
Owner Author

unmade commented Oct 28, 2022

Hey, @bigcat88

I've actually already found your library and big thanks for that!

I probably go with pi-heif though to be compliant with license. My main use-case is to make thumbnails for different image formats anyway.

I also need to read exif information from HEIC image. Currently, I'm relying on pillow _getexif method, but for HEIC it gives me AttributeError, so I need to research that a bit

Wasn't expecting someone to find that issue, so was a little bit lazy to fill in the description ;)

@bigcat88
Copy link

bigcat88 commented Oct 28, 2022

I also need to read exif information from HEIC image. Currently, I'm relying on pillow _getexif method, but for HEIC it gives me AttributeError, so I need to research that a bit

that's strange, I have tests for EXIF in repository...
metadata_exif_test.py -> getexif method from Pillow

@unmade
Copy link
Owner Author

unmade commented Oct 29, 2022

.getexif() works just as expected. However it gives significantly less information compared to private ._getexif() method regardless whether the image is heic or jpeg

@unmade
Copy link
Owner Author

unmade commented Oct 29, 2022

I probably just switch to exifread to read EXIF

@bigcat88
Copy link

bigcat88 commented Oct 29, 2022

.getexif for HEIF files give all exif info. If not then it is probably a bug - can you provide some code and a test image file to see if it is?
For JPEG as I remember it is the same.

P.S: exifread has only partial HEIF support, it will not parse .hif files(Canon cameras format) and .heif files(Nokia format). Maybe others HEIF formats too, there are so many of them except HEIC

@unmade
Copy link
Owner Author

unmade commented Oct 29, 2022

I'm testing on photos I took with iPhone 8. Here is sample images:

The .getexif() method gives me following information:

{
    'TileWidth': 512,
    'TileLength': 512,
    'GPSInfo': 1728,
    'ResolutionUnit': 2,
    'ExifOffset': 230,
    'Make': 'Apple',
    'Model': 'iPhone 8',
    'Software': '11.3.1',
    'Orientation': 1,
    'DateTime': '2018:05:28 20:35:36',
    'YCbCrPositioning': 1,
    'XResolution': 72.0,
    'YResolution': 72.0
}

The exifread gives slightly more information, such as ApertureValue, ShutterSpeedValue, etc...:

{
    'Image Make': (0x010F) ASCII=Apple @ 170,
    'Image Model': (0x0110) ASCII=iPhone 8 @ 176,
    ...
    'GPS GPSLatitudeRef': (0x0001) ASCII=N @ 1738,
    'GPS GPSLatitude': (0x0002) Ratio=[52, 22, 389/20] @ 1902,
    ...
    'EXIF ExposureTime': (0x829A) Ratio=1/873 @ 620,
    'EXIF FNumber': (0x829D) Ratio=9/5 @ 628,
    ...
}

For JPEGs images Pillow's private _getexif() method also gives that "extended" information, but public .getexif() gives the short one.

Here is a short script showing the difference between methods:
https://www.dropbox.com/s/37iq7cl0s2n22fu/exif.py?dl=0

Usage:

python3 exif.py IMG_5196.jpg

@bigcat88
Copy link

    im = Image.open("IMG_5196.HEIC")
    img_exif = im.getexif()._get_merged_dict()
    for key, val in img_exif.items():
        if key in ExifTags.TAGS:
            print(f'{ExifTags.TAGS[key]}:{val}')

@bigcat88
Copy link

@unmade
Copy link
Owner Author

unmade commented Oct 29, 2022

Works like a charm! I had to go deeper with getexif() method :)

Thank you so much for helping me out!

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

Successfully merging a pull request may close this issue.

2 participants