From edcff9ab8a370dbe4fd4814398a2b7e38459934d Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 29 Aug 2023 18:34:43 +1000 Subject: [PATCH 1/2] copy metadata into modified image --- server.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index 538f9075..1cac3281 100644 --- a/server.py +++ b/server.py @@ -12,6 +12,7 @@ import json import glob import struct from PIL import Image, ImageOps +from PIL.PngImagePlugin import PngInfo from io import BytesIO try: @@ -233,13 +234,16 @@ class PromptServer(): if os.path.isfile(file): with Image.open(file) as original_pil: + metadata = PngInfo() + for key in original_pil.text: + metadata.add_text(key, original_pil.text[key]) original_pil = original_pil.convert('RGBA') mask_pil = Image.open(image.file).convert('RGBA') # alpha copy new_alpha = mask_pil.getchannel('A') original_pil.putalpha(new_alpha) - original_pil.save(filepath, compress_level=4) + original_pil.save(filepath, compress_level=4, pnginfo=metadata) return image_upload(post, image_save_function) From 18379dea366e97105cd01685d629df83c995c150 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 29 Aug 2023 18:47:17 +1000 Subject: [PATCH 2/2] check for text attr and save --- server.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server.py b/server.py index 1cac3281..0d7d28a0 100644 --- a/server.py +++ b/server.py @@ -235,8 +235,9 @@ class PromptServer(): if os.path.isfile(file): with Image.open(file) as original_pil: metadata = PngInfo() - for key in original_pil.text: - metadata.add_text(key, original_pil.text[key]) + if hasattr(original_pil,'text'): + for key in original_pil.text: + metadata.add_text(key, original_pil.text[key]) original_pil = original_pil.convert('RGBA') mask_pil = Image.open(image.file).convert('RGBA')