Get date and time when photo was taken from EXIF data using PIL

后端 未结 7 870
隐瞒了意图╮
隐瞒了意图╮ 2020-12-13 02:16

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?

7条回答
  •  佛祖请我去吃肉
    2020-12-13 03:05

    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
    

提交回复
热议问题