Changing jpg 'date taken' to be 5 hours before existing value?

依然范特西╮ 提交于 2020-03-04 15:33:34

问题


I have some photos that were taken in a different timezone from what is needed. I need to convert the existing date taken value to be 5 hours earlier. I have some code below, but I'm unsure how to read each file's 'date taken' attribute and then subtract 5 hours from that. I thought that I could use exif to process this, like below. Im not sure how to know which format the date is stored in, or how to actually write the new date value to the 'date taken' field.

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

I saw that there is another way to do with with bash, which is preferred since this task will be scheduled. but I couldnt find jhead once installed. My machine would run the jhead.exe, but would recognize it when calling it from the command line.

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

edited for syntax

来源:https://stackoverflow.com/questions/60514748/changing-jpg-date-taken-to-be-5-hours-before-existing-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!