Skip to content

Instantly share code, notes, and snippets.

@imvaskii
Created October 4, 2018 13:34
Show Gist options
  • Save imvaskii/abcbc4a35229815bd6ce4ab7372748f9 to your computer and use it in GitHub Desktop.
Save imvaskii/abcbc4a35229815bd6ce4ab7372748f9 to your computer and use it in GitHub Desktop.
Read IPTC info from a image file in python #python #iptc
# pip install pillow
from PIL import Image, IptcImagePlugin
im = Image.open('/home/bhaskark/Pictures/iptc-test.jpg')
iptc = IptcImagePlugin.getiptcinfo(im)
if iptc:
for k, v in iptc.items():
print("{} {}".format(k, repr(v.decode())))
else:
print(" This image has no iptc info")
# We can user getter function to get values
# from specific IIM codes
# https://iptc.org/std/photometadata/specification/IPTC-PhotoMetadata
def get_caption():
return iptc.get((2,120)).decode()
print(get_caption())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment