mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-06-06 11:32:09 +08:00
Only add PNG chunks if metadata is enabled
Prevents a hypothetical scenario of a VAE being crafted to inject undesired data into PNG chunks.
This commit is contained in:
parent
a4aba18d29
commit
49aaad7c21
16
nodes.py
16
nodes.py
@ -1615,23 +1615,23 @@ class SaveImage:
|
||||
for (batch_number, image) in enumerate(images):
|
||||
i = 255. * image.cpu().numpy()
|
||||
img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
|
||||
metadata = PngInfo()
|
||||
metadata = None
|
||||
if not args.disable_metadata:
|
||||
metadata = PngInfo()
|
||||
if prompt is not None:
|
||||
metadata.add_text("prompt", json.dumps(prompt))
|
||||
if extra_pnginfo is not None:
|
||||
for x in extra_pnginfo:
|
||||
metadata.add_text(x, json.dumps(extra_pnginfo[x]))
|
||||
if hasattr(images, "png_chunks"):
|
||||
for name, data in images.png_chunks.items():
|
||||
if name in self.extra_chunks:
|
||||
metadata.add(name.lower(), data)
|
||||
else:
|
||||
metadata.add(name, data)
|
||||
if hasattr(images, "png_chunks"):
|
||||
for name, data in images.png_chunks.items():
|
||||
if name in self.extra_chunks:
|
||||
metadata.add(name.lower(), data)
|
||||
else:
|
||||
metadata.add(name, data)
|
||||
filename_with_batch_num = filename.replace("%batch_num%", str(batch_number))
|
||||
file = f"{filename_with_batch_num}_{counter:05}_.png"
|
||||
|
||||
|
||||
#TODO: revert to using img.save once Pillow supports cICP chunk
|
||||
img.encoderinfo = {"pnginfo": metadata, "compress_level": self.compress_level}
|
||||
with open(os.path.join(full_output_folder, file), 'wb') as fp:
|
||||
|
Loading…
x
Reference in New Issue
Block a user