Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 向图像添加exif日期和时间_Python_Exif - Fatal编程技术网

Python 向图像添加exif日期和时间

Python 向图像添加exif日期和时间,python,exif,Python,Exif,我有几百张照片缺少正确的createdate字段。 我需要这个,这样当我上传到谷歌照片,他们将被正确排序 幸运的是,几乎所有的照片都有另一个正确的日期字段,要么是datetimeoriginal要么是modifydate之类 我希望使用pythonexif模块扫描文件,找到最早时间的日期字段,并使用它添加createdate字段。不幸的是,该模块似乎不喜欢在不存在的地方添加新的exif字段。它的错误是: RuntimeError: only can add GPS IFD to image, n

我有几百张照片缺少正确的
createdate
字段。 我需要这个,这样当我上传到谷歌照片,他们将被正确排序

幸运的是,几乎所有的照片都有另一个正确的日期字段,要么是
datetimeoriginal
要么是
modifydate
之类

我希望使用python
exif
模块扫描文件,找到最早时间的日期字段,并使用它添加
createdate
字段。不幸的是,该模块似乎不喜欢在不存在的地方添加新的exif字段。它的错误是:

RuntimeError: only can add GPS IFD to image, not exif

对于添加缺少的字段,我还有哪些其他选项?最好使用Python,但Ruby或Go也可以:-)

您肯定应该看看命令行util。 它非常强大,所以可能根本不需要编写脚本

即使批处理任务很困难,您也可以使用
子流程
模块(
subprocess.call([“exitfool”、“param1”、“param2”])
/
子流程。检查输出([“exitfool”、“param1”、“param2”)

下面是我试图解决您的问题(命令行):

我们有一张照片
test.HEIC
。让我们看看它与日期相关的EXIF:

Olhas-MBP:Downloads olia$ exiftool test.HEIC  | grep Date

File Modification Date/Time     : 2020:07:19 21:41:19+03:00
File Access Date/Time           : 2020:07:19 21:41:19+03:00
File Inode Change Date/Time     : 2020:07:19 21:41:19+03:00
Modify Date                     : 2020:03:30 11:41:02
Date/Time Original              : 2020:03:30 11:41:02
Create Date                     : 2020:03:30 11:41:02
Profile Date Time               : 2017:07:07 13:22:32
Create Date                     : 2020:03:30 11:41:02.891+03:00
Date/Time Original              : 2020:03:30 11:41:02.891+03:00
Modify Date                     : 2020:03:30 11:41:02+03:00

因此,这张照片既有
创建日期
又有
修改日期
。让我们将“创建日期”设置为现在:

现在,让我们将“创建日期”设置为“修改日期”(不确定是否选择了正确的标记):


Olhas MBP:Downloads$exiftool-r-all=-createdate=now“-filemodifydate谢谢!这正是我需要的。
exiftool -r -all= -createdate=now "-exif:createdate<createdate" -overwrite_original test.HEIC
    1 image files updated
Olhas-MBP:Downloads olia$ exiftool test.HEIC | grep Date
File Modification Date/Time     : 2020:07:19 21:51:52+03:00
File Access Date/Time           : 2020:07:19 21:51:53+03:00
File Inode Change Date/Time     : 2020:07:19 21:51:52+03:00
Create Date                     : 2020:07:19 21:51:52+03:00
Profile Date Time               : 2017:07:07 13:22:32
Olhas-MBP:Downloads olia$ exiftool -r -all= -createdate=now "-FileModifyDate<FileCreateDate" -overwrite_original test.HEIC
    1 image files updated

Olhas-MBP:Downloads olia$ exiftool test.HEIC | grep Date
File Modification Date/Time     : 2020:07:19 21:53:19+03:00
File Access Date/Time           : 2020:07:19 21:54:09+03:00
File Inode Change Date/Time     : 2020:07:19 21:54:08+03:00
Create Date                     : 2020:07:19 21:54:08+03:00
Profile Date Time               : 2017:07:07 13:22:32

Olhas-MBP:Downloads olia$ exiftool -r -all= -createdate=now "-FileModifyDate<CreateDate" -overwrite_original test.HEIC
    1 image files updated

Olhas-MBP:Downloads olia$ exiftool test.HEIC | grep Date
File Modification Date/Time     : 2020:07:19 21:54:08+03:00
File Access Date/Time           : 2020:07:19 21:54:51+03:00
File Inode Change Date/Time     : 2020:07:19 21:54:50+03:00
Create Date                     : 2020:07:19 21:54:50+03:00
Profile Date Time               : 2017:07:07 13:22:32