Reputation: 27
I'm using some sample code trying to return the exif information from a sample .jpg image. The Python code is:
from PIL import Image
from PIL.ExifTags import TAGS
def get_exif(fn):
ret = {}
i = Image.open('C:\Users\Me\Desktop\Sample1.jpg')
info = i._getexif()
for tag, value in info.items():
decoded = TAGS.get(tag, tag)
ret[decoded] = value
return ret
The code runs with no error, but doesn't output anything. Also, tried to output it to a file, but couldn't write any info out either. Can someone spot why this isn't returning anything? Thank you!
Upvotes: 0
Views: 4572
Reputation: 3157
I don't know what you are trying to do but this code works for me (from python 2.7 and 3 onwards) :
from PIL import Image
from PIL.ExifTags import TAGS
def get_exif():
i = Image.open('/path/to/imagefile.jpg')
info = i._getexif()
return {TAGS.get(tag): value for tag, value in info.items()}
print get_exif()
Upvotes: 4