Pillow: Writing to UserComment EXIF tag for an image

Created on 24 Sep 2020  路  7Comments  路  Source: python-pillow/Pillow

I read the docs, and searched around (including searching StackOverflow) and I can't seem any documentation on adding to the UserComment EXIF field for an image. Would anyone be able to shed some light on how this can be done, if at all?

Also, would be nice to add that to the docs page!

Exif Question

All 7 comments

Hi. https://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif/usercomment.html tells us that UserComment has the value 0x9286.

from PIL import Image
im = Image.open("Tests/images/hopper.jpg")
exif = im.getexif()
exif[0x9286] = "test"
im.save("out.jpg", exif=exif)

In terms of documentation, I can offer you https://pillow.readthedocs.io/en/stable/releasenotes/6.0.0.html#added-exif-class

Thank you! Works like a charm

Just tried this with a photo that had GPS data, and I got this error:

C:\Python\lib\site-packages\PIL\TiffImagePlugin.py:592: UserWarning: Metadata Warning, tag 34853 had too many entries: 9, expected 1
  warnings.warn(

Then looking at the EXIF, the GPS data is lost, but the UserComment is retained

That sounds like #4896, which was resolved by #4862. It will be fixed in the next Pillow release, scheduled for October 15.

Oh neat. I guess I'll be back October 15! Thank you for your help!!

Let's close this as fixed by #4862, and can re-open later if necessary.

Pillow 8.0 has now been released.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mmalenta picture mmalenta  路  3Comments

indirectlylit picture indirectlylit  路  4Comments

SysoevDV picture SysoevDV  路  3Comments

amithnikhade picture amithnikhade  路  4Comments

edowson picture edowson  路  3Comments