I can get the EXIF data from an image using PIL, but how can I get the date and time that the photo was taken?
I like to use exif-py because it's pure-python, does not require compilation/installation, and works with both python 2.x and 3.x making it ideal for bundling with small portable python applications.
Link: https://github.com/ianare/exif-py
Example to get the date and time a photo was taken:
import exifread
with open('image.jpg', 'rb') as fh:
tags = exifread.process_file(fh, stop_tag="EXIF DateTimeOriginal")
dateTaken = tags["EXIF DateTimeOriginal"]
return dateTaken