added exifdata to sizelist

This commit is contained in:
2024-09-16 13:10:57 +02:00
committed by Flo Greistorfer
parent 9de971d2ac
commit a95a6e1722
2 changed files with 30 additions and 7 deletions

View File

@@ -101,7 +101,7 @@
"editor.defaultFormatter": "ms-python.black-formatter", "editor.defaultFormatter": "ms-python.black-formatter",
}, },
"black-formatter.args": [ "black-formatter.args": [
"-l 140", "-l 260",
], ],
"black-formatter.interpreter": [ "black-formatter.interpreter": [
"/usr/bin/python3", "/usr/bin/python3",

View File

@@ -6,7 +6,7 @@ from typing import Any, Dict, List, Tuple
import numpy as np import numpy as np
from tqdm.auto import tqdm from tqdm.auto import tqdm
from PIL import Image, ExifTags from PIL import Image, ExifTags, TiffImagePlugin
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
import modules.cclicense as cclicense import modules.cclicense as cclicense
@@ -55,7 +55,7 @@ def initialize_sizelist(folder: str) -> Dict[str, Dict[str, int]]:
return sizelist return sizelist
def update_sizelist(sizelist: Dict[str, Dict[str, int]], folder: str) -> None: def update_sizelist(sizelist: Dict[str, Dict[str, Any]], folder: str) -> None:
""" """
Updates the size list JSON file. Updates the size list JSON file.
@@ -86,9 +86,32 @@ def get_image_info(item: str, folder: str) -> Dict[str, Any]:
with Image.open(os.path.join(folder, item)) as img: with Image.open(os.path.join(folder, item)) as img:
exif = img.getexif() exif = img.getexif()
width, height = img.size width, height = img.size
exifdata = {ExifTags.TAGS.get(key, key): val for key, val in exif.items()} if exif:
ifd = exif.get_ifd(ExifTags.IFD.Exif)
exifdatas = {key: val for key, val in exif.items()} | ifd
exifdata = {}
for tag_id in exifdatas:
tag = ExifTags.TAGS.get(tag_id, tag_id)
content = exifdatas.get(tag_id)
if isinstance(content, bytes):
content = content.hex(" ")
if isinstance(content, TiffImagePlugin.IFDRational):
content = content.limit_rational(1000000)
if isinstance(content, tuple):
newtuple = ()
for i in content:
if isinstance(i, TiffImagePlugin.IFDRational):
newtuple = newtuple + (i.limit_rational(1000000),)
if newtuple:
content = newtuple
exifdata[tag] = content
if "Orientation" in exifdata and exifdata["Orientation"] in [6, 8]: if "Orientation" in exifdata and exifdata["Orientation"] in [6, 8]:
width, height = height, width width, height = height, width
for key in ["PrintImageMatching", "UserComment", "MakerNote"]:
if key in exifdata:
del exifdata[key]
return {"width": width, "height": height, "exifdata": exifdata}
else:
return {"width": width, "height": height} return {"width": width, "height": height}