python解析照片拍摄时间

Posted 帅胡

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python解析照片拍摄时间相关的知识,希望对你有一定的参考价值。

首先需要安装exifread库。通过EXIF(Exchangeable image file format: 可交换图像文件格式) 获取这些信息。

获取图片时间信息:

import exifread
with open(file_path, \'rb\') as file_data:
    tags = exifread.process_file(file_data)
    tag_date = \'EXIF DateTimeOriginal\'
    if tag_date in tags:
        file_rename =str(tags[tag_date]).replace(\':\',\'\').replace(\' \', \'_\') + os.path.splitext(filename)[1]
        new_path = os.path.join(root_dir, file_rename)
        os.rename(file_path, new_path)

  通过以上代码即可获取拍摄时间,得到时间格式:2022:03:11 11:30:06

以上是关于python解析照片拍摄时间的主要内容,如果未能解决你的问题,请参考以下文章