Skip to content

Commit

Permalink
Support RGB mode, compression
Browse files Browse the repository at this point in the history
  • Loading branch information
catboxanon committed Sep 27, 2024
1 parent 6ff7f52 commit e9ba128
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions js/assets/pako.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,9 @@ app.registerExtension({
}
});
},
async setup() {
const script = document.createElement("script");
script.src = new URL(`assets/pako.min.js`, import.meta.url);
document.body.append(script);
},
});
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "comfyui_stealth_pnginfo"
description = "Read and write 'stealth metadata' in PNG files"
version = "1.0.2"
version = "1.1.0"

[project.urls]
Repository = "https://github.com/catboxanon/comfyui_stealth_pnginfo"
Expand Down
9 changes: 6 additions & 3 deletions stealth.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def INPUT_TYPES(s):
"required": {
"images": ("IMAGE", {"tooltip": "The images to save."}),
"filename_prefix": ("STRING", {"default": "ComfyUI-Stealth", "tooltip": "The prefix for the file to save. This may include formatting information such as %date:yyyy-MM-dd% or %Empty Latent Image.width% to include values from nodes."}),
"mode": (["alpha", "rgb"], {"default": "alpha"}),
"compressed": ("BOOLEAN", {"default": True, "tooltip": "Compress the metadata using gzip."}),
"only_stealth": ("BOOLEAN", {"default": False, "tooltip": "Only save stealth metadata (no PNG tEXt chunks)"}),
},
"hidden": {
Expand All @@ -29,7 +31,7 @@ def INPUT_TYPES(s):

DESCRIPTION = "Saves the input images to your ComfyUI output directory, with metadata additionally written to the alpha channel."

def save_images(self, images, filename_prefix="ComfyUI-Stealth", prompt=None, extra_pnginfo=None, only_stealth=False):
def save_images(self, images, filename_prefix="ComfyUI-Stealth", prompt=None, extra_pnginfo=None, mode="alpha", compressed=True, only_stealth=False):
filename_prefix += self.prefix_append
full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir, images[0].shape[1], images[0].shape[0])
results = list()
Expand All @@ -49,8 +51,9 @@ def save_images(self, images, filename_prefix="ComfyUI-Stealth", prompt=None, ex
if not only_stealth:
metadata.add_text(x, json.dumps(extra_pnginfo[x]))
stealth_metadata[x] = json.dumps(extra_pnginfo[x])
img.putalpha(Image.new("L", img.size, 255))
img = stealth_write(img, json.dumps(stealth_metadata))
if mode == "alpha":
img.putalpha(Image.new("L", img.size, 255))
img = stealth_write(img, json.dumps(stealth_metadata), mode, compressed)

filename_with_batch_num = filename.replace("%batch_num%", str(batch_number))
file = f"{filename_with_batch_num}_{counter:05}_.png"
Expand Down

0 comments on commit e9ba128

Please sign in to comment.