hMatoba / Piexif

Exif manipulation with pure python script.
MIT License
367 stars 81 forks source link

Read `UserComment` when opened with Pillow #62

Closed faroit closed 6 years ago

faroit commented 6 years ago

I save UserComment data with piexif using the UserComment helper and dump it as exif bytes and write to jpg using pillow.

When I load the jpg with pillow, what is the best way to extract the UserComment using piexif without opening the file again (because its already opened with pillow)?

For now I came up with the following:

img = Image.open(buf)
exif_data = img._getexif()
piexif.helper.UserComment.load(exif_data[piexif.ExifIFD.UserComment])

is that how it is intended to work?

hMatoba commented 6 years ago

Use piexif's dict.

exif_data = piexif.load(img.info["exif"])

http://piexif.readthedocs.io/en/latest/sample.html#with-pil-pillow

faroit commented 6 years ago

alright, thanks