fix for failing to save 4chan downscale for large iamges

This commit is contained in:
AUTOMATIC 2022-09-15 14:54:29 +03:00
parent b28cf84c36
commit 6d2eb339d6
1 changed files with 8 additions and 7 deletions

View File

@ -345,16 +345,17 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i
if not os.path.exists(fullfn): if not os.path.exists(fullfn):
break break
if extension.lower() in ("jpg", "jpeg", "webp"): def exif_bytes():
exif_bytes = piexif.dump({ return piexif.dump({
"Exif": { "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 target_side_length = 4000
oversize = image.width > target_side_length or image.height > target_side_length 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: elif oversize:
image = image.resize((image.width * target_side_length // image.height, target_side_length), LANCZOS) 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: if opts.save_txt and info is not None:
with open(f"{fullfn_without_extension}.txt", "w", encoding="utf8") as file: with open(f"{fullfn_without_extension}.txt", "w", encoding="utf8") as file: