From 7defc44cde983665c03ff8982fcad0765def2383 Mon Sep 17 00:00:00 2001 From: justumen Date: Tue, 10 Sep 2024 09:32:15 +0200 Subject: [PATCH] 0.19 --- README.md | 3 ++- pyproject.toml | 2 +- save_img_to_folder.py | 18 +++++++++++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e6b778e..698e992 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 🔗 Comfyui : Bjornulf_custom_nodes v0.18 🔗 +# 🔗 Comfyui : Bjornulf_custom_nodes v0.19 🔗 # Dependencies @@ -28,6 +28,7 @@ - **v0.16**: Big changes on Character Description Generator - **v0.17**: New loop node, combine by lines. - **v0.18**: New loop node, Free VRAM hack +- **v0.19**: Changes for save to folder node : ignore missing images filenames, will use the highest number found + 1. # 📝 Nodes descriptions diff --git a/pyproject.toml b/pyproject.toml index 320ddbb..386d910 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "bjornulf_custom_nodes" description = "Nodes: Ollama, Text to Speech, Save image for Bjornulf LobeChat, Text with random Seed, Random line from input, Combine images (Background+Overlay alpha), Image to grayscale (black & white), Remove image Transparency (alpha), Resize Image, ..." -version = "0.18" +version = "0.19" license = {file = "LICENSE"} [project.urls] diff --git a/save_img_to_folder.py b/save_img_to_folder.py index 18662ef..584990e 100644 --- a/save_img_to_folder.py +++ b/save_img_to_folder.py @@ -25,6 +25,15 @@ class SaveImageToFolder: os.makedirs(output_dir, exist_ok=True) results = [] + + # Find the highest existing file number + existing_files = [f for f in os.listdir(output_dir) if f.endswith('.png') and f[:5].isdigit()] + if existing_files: + highest_num = max(int(f[:5]) for f in existing_files) + counter = highest_num + 1 + else: + counter = 1 + for image in images: i = 255. * image.cpu().numpy() img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8)) @@ -36,15 +45,10 @@ class SaveImageToFolder: for k, v in extra_pnginfo.items(): metadata.add_text(k, json.dumps(v)) - counter = 1 - while True: - filename = os.path.join(output_dir, f"{counter:05d}.png") - if not os.path.exists(filename): - break - counter += 1 - + filename = os.path.join(output_dir, f"{counter:05d}.png") img.save(filename, format="PNG", pnginfo=metadata) print(f"Image saved as: {filename}") results.append({"filename": filename}) + counter += 1 return {"ui": {"images": [{"filename": filename, "type": "output"}]}} \ No newline at end of file