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):
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: