Created
October 4, 2018 13:34
-
-
Save imvaskii/abcbc4a35229815bd6ce4ab7372748f9 to your computer and use it in GitHub Desktop.
Read IPTC info from a image file in python #python #iptc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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