fix: add PIL fallback for CR2 EXIF (piexif alone can't parse some CR2)

This commit is contained in:
admin committed 2026-06-28 18:16:58 +02:00
1 parent 5054542aff
commit c0bd6acda6
1 file changed
+16
+16
View File
@@ -196,6 +196,22 @@ def _read_cr2_exif(path: Path) -> str | None:
return raw_val.decode('utf-8')
except Exception:
pass
# Fallback: PIL can read EXIF from CR2's embedded JPEG preview
try:
from PIL import Image
from PIL.ExifTags import TAGS
img = Image.open(path)
raw = img._getexif()
img.close()
if raw:
tag_map = {v: k for k, v in TAGS.items()}
for tag_name in ('DateTimeOriginal', 'DateTime'):
tag_code = tag_map.get(tag_name)
if tag_code and tag_code in raw:
return raw[tag_code]
except Exception:
pass
return None