Mac下JPEG照片的时间日期纠正
生活随笔
收集整理的這篇文章主要介紹了
Mac下JPEG照片的时间日期纠正
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
之前把照片保存在百度網盤上了,重新下載之后照片的創建時間變成了下載時間。但是EXIF中的創建時間是正確的??墒茿pple的照片程序竟然顯示的是照片的文件創建時間而不是EXIF中的時間,開始以為這是一個Bug,后來明白了,應該是Apple的用戶的隱私策略限制,不能讀取用戶的文件(至少看起來是這樣的)。而百度網盤似乎就不太在乎這些,在百度網盤上的文件是會自動按EXIF文件中的時間整理的。
為此,寫了一個python腳本,讀取JPEG的EXIF中的原始創建時間,改寫文件的創建時間和文件名。
from PIL import Image import exifread import osdef renameFile(fileName, newName):if fileName == newName:returntot = 1while os.path.exists(newName):newName = os.path.split(fileName)[0] + "_" + str(tot) + os.path.split(fileName)[1]tot += 1os.rename(fileName, newName)def editFileCtime(filePath, timeStr):print("====editFileCtime")ctime = timeStr.replace(':', '').replace(' ', '')ctime = ctime[:-2] + "." + ctime[-2:]os.system("touch -t " + ctime + " " + filePath)def getCreateTime(filename):print("====getCreateTime")FIELD = 'EXIF DateTimeOriginal'fd = open(filename, 'rb')tags = exifread.process_file(fd)fd.close()print("fileName:", filename)if FIELD in tags:print(tags[FIELD])return tags[FIELD]else:print('No {} found'.format(FIELD))return Noneif __name__ == "__main__":for filename in os.listdir('.'):if os.path.isfile(filename):createTime = getCreateTime(filename)if createTime:editFileCtime(filename, str(createTime))new_name = str(createTime).replace(':', '').replace(' ', '_') + os.path.splitext(filename)[1]renameFile(filename, new_name)總結
以上是生活随笔為你收集整理的Mac下JPEG照片的时间日期纠正的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【自动化运维】从0到1 CICD自动化部
- 下一篇: BT控制面板cpu,内存使用率时常达到1