Correct support for JPG images

This commit is contained in:
Benjamin Loison 2024-04-27 15:55:25 +02:00
parent e9038bdb76
commit bd0b9aca94
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -10,18 +10,24 @@ from PIL.ExifTags import TAGS
import os
os.chdir('photos')
path = 'photos'
os.chdir(path)
names = []
dates = []
for fileName in sorted(os.listdir()):
image = Image.open(fileName)
try:
image = Image.open(fileName)
except:
# Skip raw images.
continue
imageExif = image.getexif()
dateTimeKey = list(TAGS.keys())[list(TAGS.values()).index('DateTime')]
dateTime = imageExif[dateTimeKey]
names += [fileName.replace('DSC0', '').replace('.JPG', '')]
dates += [dateTime[:(-1 if fileName.endswith('.tif') else 0)]]
dates += [dateTime[:(-1 if fileName.endswith('.tif') else len(dateTime))]]
# Convert date strings to datetime
dates = [datetime.strptime(d, "%Y:%m:%d %H:%M:%S") for d in dates]