updates for exif comments #446

This commit is contained in:
AUTOMATIC 2022-09-14 15:20:05 +03:00
parent c4e90bf689
commit bb2732c1c7
2 changed files with 8 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import modules.gfpgan_model
from modules.ui import plaintext_to_html from modules.ui import plaintext_to_html
import modules.codeformer_model import modules.codeformer_model
import piexif import piexif
import piexif.helper
cached_images = {} cached_images = {}
@ -80,7 +81,12 @@ def run_pnginfo(image):
if "exif" in image.info: if "exif" in image.info:
exif = piexif.load(image.info["exif"]) exif = piexif.load(image.info["exif"])
exif_comment = (exif or {}).get("Exif", {}).get(piexif.ExifIFD.UserComment, b'') exif_comment = (exif or {}).get("Exif", {}).get(piexif.ExifIFD.UserComment, b'')
exif_comment = exif_comment.decode("utf8", 'ignore') try:
exif_comment = piexif.helper.UserComment.load(exif_comment)
except ValueError:
exif_comment = exif_comment.decode('utf8', errors="ignore")
items['exif comment'] = exif_comment items['exif comment'] = exif_comment
for field in ['jfif', 'jfif_version', 'jfif_unit', 'jfif_density', 'dpi', 'exif']: for field in ['jfif', 'jfif_version', 'jfif_unit', 'jfif_density', 'dpi', 'exif']:

View File

@ -325,7 +325,7 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i
if extension.lower() in ("jpg", "jpeg", "webp"): if extension.lower() in ("jpg", "jpeg", "webp"):
exif_bytes = piexif.dump({ exif_bytes = piexif.dump({
"Exif": { "Exif": {
piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(info) piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(info, encoding="unicode")
}, },
}) })
else: else: