From f517838c75014f981ae1c41f1bc776d74daf9a23 Mon Sep 17 00:00:00 2001 From: Keith <1868690+wk5ovc@users.noreply.github.com> Date: Mon, 15 May 2023 10:47:01 +0800 Subject: [PATCH] Fix extra networks save preview image geninfo --- modules/ui_extra_networks.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/ui_extra_networks.py b/modules/ui_extra_networks.py index 8c3dea564..9e6e05313 100644 --- a/modules/ui_extra_networks.py +++ b/modules/ui_extra_networks.py @@ -334,9 +334,19 @@ def setup_ui(ui, gallery): assert is_allowed, f'writing to {filename} is not allowed' if geninfo: - pnginfo_data = PngImagePlugin.PngInfo() - pnginfo_data.add_text('parameters', geninfo) - image.save(filename, pnginfo=pnginfo_data) + ext = os.path.splitext(filename)[1].lower() + if ext == '.png': + pnginfo_data = PngImagePlugin.PngInfo() + pnginfo_data.add_text('parameters', geninfo) + image.save(filename, pnginfo=pnginfo_data) + elif ext in ('.jpg', '.jpeg', '.webp'): + exif_bytes = piexif.dump({ + 'Exif': {piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(geninfo or '', + encoding='unicode')} + }) + image.save(filename, exif=exif_bytes, quality=shared.opts.jpeg_quality) + else: + image.save(filename) else: image.save(filename)