From 6d2eb339d650d3a6d9e4c8f5222d5080b526e7d2 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Thu, 15 Sep 2022 14:54:29 +0300 Subject: [PATCH] fix for failing to save 4chan downscale for large iamges --- modules/images.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/images.py b/modules/images.py index 1c01d6d8..91a58610 100644 --- a/modules/images.py +++ b/modules/images.py @@ -345,16 +345,17 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i if not os.path.exists(fullfn): break - if extension.lower() in ("jpg", "jpeg", "webp"): - exif_bytes = piexif.dump({ + def exif_bytes(): + return piexif.dump({ "Exif": { - piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(info, encoding="unicode") + piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(info or "", encoding="unicode") }, }) - else: - exif_bytes = None - image.save(fullfn, quality=opts.jpeg_quality, pnginfo=pnginfo, exif=exif_bytes) + if extension.lower() in ("jpg", "jpeg", "webp"): + image.save(fullfn, quality=opts.jpeg_quality, exif_bytes=exif_bytes()) + else: + image.save(fullfn, quality=opts.jpeg_quality, pnginfo=pnginfo) target_side_length = 4000 oversize = image.width > target_side_length or image.height > target_side_length @@ -366,7 +367,7 @@ 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, quality=opts.jpeg_quality, exif=exif_bytes) + image.save(fullfn_without_extension + ".jpg", quality=opts.jpeg_quality, exif_bytes=exif_bytes()) if opts.save_txt and info is not None: with open(f"{fullfn_without_extension}.txt", "w", encoding="utf8") as file: