Merge branch 'preserve-pnginfo' of https://github.com/chrisgoringe/ComfyUI

This commit is contained in:
comfyanonymous 2023-08-29 11:32:58 -04:00
commit 66c690e698

View File

@ -12,6 +12,7 @@ import json
import glob import glob
import struct import struct
from PIL import Image, ImageOps from PIL import Image, ImageOps
from PIL.PngImagePlugin import PngInfo
from io import BytesIO from io import BytesIO
try: try:
@ -233,13 +234,17 @@ class PromptServer():
if os.path.isfile(file): if os.path.isfile(file):
with Image.open(file) as original_pil: with Image.open(file) as original_pil:
metadata = PngInfo()
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') original_pil = original_pil.convert('RGBA')
mask_pil = Image.open(image.file).convert('RGBA') mask_pil = Image.open(image.file).convert('RGBA')
# alpha copy # alpha copy
new_alpha = mask_pil.getchannel('A') new_alpha = mask_pil.getchannel('A')
original_pil.putalpha(new_alpha) 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) return image_upload(post, image_save_function)