ImageUtils.py 398 B

123456789101112131415
  1. from datetime import datetime
  2. from PIL import Image
  3. def get_image_date(img_path: str) -> datetime:
  4. """Returns the date from the image EXIF data.
  5. Args:
  6. img_path (str): path to image
  7. Returns:
  8. datetime: datetime extracted from EXIF data
  9. """
  10. img = Image.open(img_path)
  11. date_raw = img.getexif()[306]
  12. return datetime.strptime(date_raw, "%Y:%m:%d %H:%M:%S")