DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Reading And Writing Image Metadata

09.29.2005
| 15383 views |
  • submit to reddit
        The IPTCInfo module allows you to add/edit metadata 
to your image. You can download it from <a href=http://cheeseshop.python.org/pypi/IPTCInfo/>here</a>.

Reading
from iptcinfo import IPTCInfo
info = IPTCInfo('test.jpg')
print info.keywords, info.supplementalCategories, info.contacts
caption = info.data['caption/abstract']
Add/Edit
info = IPTCInfo('test.jpg')
info.data['caption/abstract'] = 'Witty caption here'
info.data['supplemental category'] = ['portrait']
info.save()
info.saveAs('test_out.jpg')  # keep original safe