the last PR broke saving EXiF completely for me. I don't know if it was broken already or some condition changed, but it seems like the person who originally added EXIF said, saving it with PIL may not work. I switched to using piexif to add data after the file written.

This commit is contained in:
AUTOMATIC 2022-09-17 08:32:15 +03:00
parent 4f1f348b6a
commit 3c665b8dd6

View file

@ -346,6 +346,7 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i
break
def create_exif_bytes():
def exif_bytes():
return piexif.dump({
"Exif": {
piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(info or "", encoding="unicode")
@ -353,14 +354,12 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i
})
if extension.lower() in ("jpg", "jpeg", "webp"):
exif_bytes = create_exif_bytes()
image.save(fullfn, quality=opts.jpeg_quality, exif=exif_bytes)
image.save(fullfn, quality=opts.jpeg_quality)
if opts.enable_pnginfo and info is not None:
piexif.insert(exif_bytes(), fullfn)
else:
image.save(fullfn, quality=opts.jpeg_quality, pnginfo=pnginfo)
if extension.lower() == "webp":
piexif.insert(exif_bytes, fullfn)
target_side_length = 4000
oversize = image.width > target_side_length or image.height > target_side_length
if opts.export_for_4chan and (oversize or os.stat(fullfn).st_size > 4 * 1024 * 1024):
@ -371,11 +370,9 @@ 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)
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)
image.save(fullfn_without_extension + ".jpg", quality=opts.jpeg_quality)
if opts.enable_pnginfo and info is not None:
piexif.insert(exif_bytes(), fullfn)
if opts.save_txt and info is not None:
with open(f"{fullfn_without_extension}.txt", "w", encoding="utf8") as file: