Python 更改jpg';拍摄日期';在现有值之前5小时?
我有一些照片是在不同的时区拍摄的。我需要将现有的日期取值转换为提前5小时。下面我有一些代码,但我不确定如何读取每个文件的“date Take”属性,然后从中减去5小时。我想我可以使用exif来处理这个问题,如下所示。我不知道如何知道日期存储的格式,或者如何将新的日期值写入“date Take”字段Python 更改jpg';拍摄日期';在现有值之前5小时?,python,bash,time,attributes,Python,Bash,Time,Attributes,我有一些照片是在不同的时区拍摄的。我需要将现有的日期取值转换为提前5小时。下面我有一些代码,但我不确定如何读取每个文件的“date Take”属性,然后从中减去5小时。我想我可以使用exif来处理这个问题,如下所示。我不知道如何知道日期存储的格式,或者如何将新的日期值写入“date Take”字段 import os import glob from exif import Image rootdir = r'C:\Users\Me\Desktop\test_dir' #18,000 seco
import os
import glob
from exif import Image
rootdir = r'C:\Users\Me\Desktop\test_dir'
#18,000 seconds = 5 hours
for subdir, dirs, files in os.walk(rootdir):
for file in files:
if file.endswith(".jpg") or file.endswith(".jpeg"):
old_time = file.datetime
new_time = old_time - 18000
#not sure how to write new_time to the date taken attribute
file.write(file.new_time)
else:
continue
我看到有,这是首选,因为这项任务将被安排。但是一旦安装了jhead,我就找不到了。我的机器将运行jhead.exe,但在从命令行调用它时会识别它
shopt -s nullglob
for dir in C:\Users\Me\Desktop\test_dir*/
do
for file in "$dir"/*
do
if f in *.jpg
then
jhead -ta-0:05:00 *.jpg
fi
done
done
pause
为语法编辑显示一些文件名和所需的文件名。@cyrus I--不--想在文件名中添加时间。我只想更改照片属性。