From 4f1f348b6a23e46b4f7ce87a4137836399514f65 Mon Sep 17 00:00:00 2001 From: JJ Date: Fri, 16 Sep 2022 07:28:57 +1000 Subject: [PATCH] image.save parameter fix * image.save takes exif as a parameter * piexif takes the bytes as a parameter, not the exif_bytes function itself * reduce calls to create_exif_bytes --- modules/images.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/images.py b/modules/images.py index f37f5f08..8cd7fe37 100644 --- a/modules/images.py +++ b/modules/images.py @@ -345,7 +345,7 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i if not os.path.exists(fullfn): break - def exif_bytes(): + def create_exif_bytes(): return piexif.dump({ "Exif": { piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(info or "", encoding="unicode") @@ -353,7 +353,8 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i }) if extension.lower() in ("jpg", "jpeg", "webp"): - image.save(fullfn, quality=opts.jpeg_quality, exif_bytes=exif_bytes()) + exif_bytes = create_exif_bytes() + image.save(fullfn, quality=opts.jpeg_quality, exif=exif_bytes) else: image.save(fullfn, quality=opts.jpeg_quality, pnginfo=pnginfo) @@ -370,7 +371,11 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i elif oversize: image = image.resize((image.width * target_side_length // image.height, target_side_length), LANCZOS) - image.save(fullfn_without_extension + ".jpg", quality=opts.jpeg_quality, exif_bytes=exif_bytes()) + if exif_bytes in locals(): + pass + else: + exif_bytes = create_exif_bytes() + image.save(fullfn_without_extension + ".jpg", quality=opts.jpeg_quality, exif=exif_bytes) if opts.save_txt and info is not None: with open(f"{fullfn_without_extension}.txt", "w", encoding="utf8") as file: