Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.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 更改jpg';拍摄日期';在现有值之前5小时?_Python_Bash_Time_Attributes - Fatal编程技术网

Python 更改jpg';拍摄日期';在现有值之前5小时?

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

我有一些照片是在不同的时区拍摄的。我需要将现有的日期取值转换为提前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 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--不--想在文件名中添加时间。我只想更改照片属性。