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

PNG and TIFF XMP #5531

Closed
trougnouf opened this issue Jun 9, 2021 · 5 comments · Fixed by #5455
Closed

PNG and TIFF XMP #5531

trougnouf opened this issue Jun 9, 2021 · 5 comments · Fixed by #5455
Labels

Comments

@trougnouf
Copy link

trougnouf commented Jun 9, 2021

What did you do?

Download a PNG file with exif data, for example https://commons.wikimedia.org/wiki/File:Ares_Tower_Vienna_from_SW_on_2015-07-10.png (direct link: https://upload.wikimedia.org/wikipedia/commons/5/5c/Ares_Tower_Vienna_from_SW_on_2015-07-10.png )

from PIL import Image
infpath = 'Ares Tower Vienna from SW on 2015-07-10.png'
pilimg = Image.open(infpath)
exifdata = pilimg._getexif()

What did you expect to happen?

exifdata[34855] == 100 # ISO sensitivity

See alse: #3674

What actually happened?

exifdata is None.

pilimg.info has the following keys: ['dpi', 'icc_profile', 'XML:com.adobe.xmp', 'chromaticity']; XML:com.adobe.xmp contains all of the info, but it is a very messy xml string.

What are your OS, Python and Pillow versions?

  • OS: Arch Linux
  • Python: 3.9.5
  • Pillow: 8.2.0

On a side note I can't get exif info directly from a tiff file either, _getexif() then raises an AttributeError. egfile: https://commons.wikimedia.org/wiki/File:Book_of_Hours_(Use_of_Metz)_Fol._27r,_Decorated_Initials.tif (direct: https://upload.wikimedia.org/wikipedia/commons/1/16/Book_of_Hours_%28Use_of_Metz%29_Fol._27r%2C_Decorated_Initials.tif )

@trougnouf trougnouf changed the title _getexif not working with png files _getexif() not working with png files Jun 9, 2021
@radarhere
Copy link
Member

If I run exiftool -v over your PNG, I find that ISO is not within an eXIf chunk, but within a iTXt chunk, 'XMP directory' - as you've already figured out in a different way. So my conclusion is that the information you're after is not technically EXIF.

In 8.2.0 (#5144), we added getxmp() for JPEG images, to present XMP info in a nicer form. If we added that method for PNG as well, does that sound like a good solution?

@radarhere
Copy link
Member

As for your TIFF image, as the error says, Pillow doesn't have a _getexif() method for TIFF.
I'm guessing that the information you're after is in the Image.open('sample.tif').tag_v2 dictionary.
You may also be interested in #5416, a pending PR to allow the tag_v2 data to be accessed through getexif().

@trougnouf
Copy link
Author

In 8.2.0 (#5144), we added getxmp() for JPEG images, to present XMP info in a nicer form. If we added that method for PNG as well, does that sound like a good solution?

Yes, that would be pretty ideal :) Anything that uniformizes tag access across different formats is a step in the right direction imo.

It would be nice to have it accessible through the same method with tiff tag_v2 data as well.

@radarhere radarhere changed the title _getexif() not working with png files PNG and TIFF XMP Jun 9, 2021
@radarhere radarhere added the TIFF label Jun 10, 2021
@radarhere
Copy link
Member

I've added getxmp() methods for PNG and TIFF into #5455. See what you think.

@radarhere
Copy link
Member

Pillow 8.3.0 has now been released with this new feature.

However, be aware that you will have to install defusedxml to get it to work. See #5565 for more information

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

Successfully merging a pull request may close this issue.

2 participants