diff --git a/.gitignore b/.gitignore index f47dea9..f410023 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ web/js/clear_vram.js CUSTOM_STRING.py.txt web/js/BJORNULF_TYPES.js.txt web/js/CUSTOM_STRING.js.txt +save_api_image.py.txt \ No newline at end of file diff --git a/README.md b/README.md index 13953a3..08c4d07 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# πŸ”— Comfyui : Bjornulf_custom_nodes v0.6 πŸ”— +# πŸ”— Comfyui : Bjornulf_custom_nodes v0.7 πŸ”— # Dependencies @@ -13,6 +13,7 @@ - **v0.5**: New node : Remove image transparency (alpha) - Fill alpha channel with solid color. - **v0.5**: New node : Image to grayscale (black & white) - Convert an image to grayscale. - **v0.6**: New node : Combine images (Background + Overlay) - Combine two images into a single image. +- **v0.7**: Replace Save API node with Save Bjornulf Lobechat node. (For my custom lobe-chat) # πŸ“ Nodes descriptions @@ -97,20 +98,21 @@ Resize an image to exact dimensions. The other node will save the image to the e **Description:** Save the given text input to a file. Useful for logging and storing text data. -## 16 - πŸ–Ό Save image for API (❗For my custom [lobe-chat](https://github.com/justUmen/lobe-chat)❗) -![Save API](screenshots/save_api.png) +## 16 - πŸ–ΌπŸ’¬ Save image for Bjornulf LobeChat (❗For my custom [lobe-chat](https://github.com/justUmen/Bjornulf_lobe-chat)❗) +![Save Bjornulf Lobechat](screenshots/save_bjornulf_lobechat.png) **Description:** -It will save the image with the name of `api_next_image.txt`, which will be incremented each time you run the node. +❓ I made that node for my custom lobe-chat to send+receive images from Comfyui API : [lobe-chat](https://github.com/justUmen/Bjornulf_lobe-chat) +It will save the image in the folder `output/BJORNULF_LOBECHAT/`. The name will start at `api_00001.png`, then `api_00002.png`, etc... -❓ I made that for my custom lobe-chat to send+receive images from Comfyui API : [lobe-chat](https://github.com/justUmen/lobe-chat) +It will also create a link to the last generated image at the location `output/BJORNULF_API_LAST_IMAGE.png`. +This link will be used by my custom lobe-chat to copy the image inside the lobe-chat project. ## 17 - πŸ–Ό Save image as `tmp_api.png` Temporary API βš οΈπŸ’£ ![Save Temporary API](screenshots/save_tmp_api.png) **Description:** -Save image for short-term use : ./output/tmp_api.png βš οΈπŸ’£ - +Save image for short-term use : ./output/tmp_api.png βš οΈπŸ’£ ## 18 - πŸ–ΌπŸ“ Save image to a chosen folder name ![Save Temporary API](screenshots/save_image_to_folder.png) diff --git a/__init__.py b/__init__.py index de4c70f..53bf379 100644 --- a/__init__.py +++ b/__init__.py @@ -21,13 +21,15 @@ from .show_float import ShowFloat from .save_text import SaveText from .save_tmp_image import SaveTmpImage from .save_image_path import SaveImagePath -from .save_api_image import SaveApiImage +# from .save_api_image import SaveApiImage from .save_img_to_folder import SaveImageToFolder from .resize_image import ResizeImage from .loop_my_combos_samplers_schedulers import LoopCombosSamplersSchedulers from .remove_transparency import RemoveTransparency from .image_to_grayscale import GrayscaleTransform from .combine_background_overlay import CombineBackgroundOverlay +from .save_bjornulf_lobechat import SaveBjornulfLobeChat +# from .check_black_image import CheckBlackImage # from .clear_vram import ClearVRAM # from .CUSTOM_STRING import CustomStringType @@ -35,7 +37,9 @@ from .combine_background_overlay import CombineBackgroundOverlay NODE_CLASS_MAPPINGS = { # "Bjornulf_CustomStringType": CustomStringType, "Bjornulf_ollamaLoader": ollamaLoader, + # "Bjornulf_CheckBlackImage": CheckBlackImage, # "Bjornulf_ClearVRAM": ClearVRAM, + "Bjornulf_SaveBjornulfLobeChat": SaveBjornulfLobeChat, "Bjornulf_WriteText": WriteText, "Bjornulf_RemoveTransparency": RemoveTransparency, "Bjornulf_GrayscaleTransform": GrayscaleTransform, @@ -52,7 +56,7 @@ NODE_CLASS_MAPPINGS = { "Bjornulf_SaveImageToFolder": SaveImageToFolder, "Bjornulf_SaveTmpImage": SaveTmpImage, "Bjornulf_SaveImagePath": SaveImagePath, - "Bjornulf_SaveApiImage": SaveApiImage, + # "Bjornulf_SaveApiImage": SaveApiImage, "Bjornulf_CombineTexts": CombineTexts, "Bjornulf_LoopTexts": LoopTexts, "Bjornulf_RandomTexts": RandomTexts, @@ -70,6 +74,8 @@ NODE_CLASS_MAPPINGS = { NODE_DISPLAY_NAME_MAPPINGS = { # "Bjornulf_CustomStringType": "!!! CUSTOM STRING TYPE !!!", "Bjornulf_ollamaLoader": "πŸ¦™ Ollama (Description)", + # "Bjornulf_CheckBlackImage": "πŸ”² Check Black Image (Empty mask)", + "Bjornulf_SaveBjornulfLobeChat": "πŸ–ΌπŸ’¬ Save image for Bjornulf LobeChat", # "Bjornulf_ClearVRAM": "🧹 Clear VRAM", "Bjornulf_ShowText": "πŸ‘ Show (Text)", "Bjornulf_ShowInt": "πŸ‘ Show (Int)", @@ -81,7 +87,7 @@ NODE_DISPLAY_NAME_MAPPINGS = { "Bjornulf_SaveImagePath": "πŸ–Ό Save Image (exact path, exact name) βš οΈπŸ’£", "Bjornulf_SaveImageToFolder": "πŸ–ΌπŸ“ Save Image to a folder", "Bjornulf_SaveTmpImage": "πŸ–Ό Save Image (tmp_api.png) βš οΈπŸ’£", - "Bjornulf_SaveApiImage": "πŸ–Ό Save Image (./output/api_00001.png...)", + # "Bjornulf_SaveApiImage": "πŸ–Ό Save Image (./output/api_00001.png...)", "Bjornulf_SaveText": "πŸ’Ύ Save Text", #Make SaveCharacter, SaveLocation, SaveCamera, SaveAction, SaveClothes, SaveEmotion... "Bjornulf_LoadText": "πŸ“₯ Load Text", #Make LoadCharacter, LoadLocation, LoadCamera, LoadAction, LoadClothes, LoadEmotion... "Bjornulf_WriteText": "βœ’ Write Text", diff --git a/save_api_image.py b/save_bjornulf_lobechat.py similarity index 67% rename from save_api_image.py rename to save_bjornulf_lobechat.py index 2967d70..7916e11 100644 --- a/save_api_image.py +++ b/save_bjornulf_lobechat.py @@ -4,7 +4,7 @@ from PIL import Image import json from PIL.PngImagePlugin import PngInfo -class SaveApiImage: +class SaveBjornulfLobeChat: @classmethod def INPUT_TYPES(cls): return { @@ -14,14 +14,15 @@ class SaveApiImage: "hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"}, } - FUNCTION = "save_api_image" + FUNCTION = "save_bjornulf_lobe_chat" RETURN_TYPES = () OUTPUT_NODE = True CATEGORY = "Bjornulf" - def save_api_image(self, image, prompt=None, extra_pnginfo=None): + def save_bjornulf_lobe_chat(self, image, prompt=None, extra_pnginfo=None): # Ensure the output directory exists - os.makedirs("./output/", exist_ok=True) + output_dir = "./output/BJORNULF_LOBECHAT/" + os.makedirs(output_dir, exist_ok=True) # Convert the image from ComfyUI format to PIL Image i = 255. * image.cpu().numpy() @@ -35,11 +36,14 @@ class SaveApiImage: # Determine the next available filename counter = 1 while True: - filename = f"./output/api_{counter:05d}.png" + filename = f"{output_dir}api_{counter:05d}.png" if not os.path.exists(filename): break counter += 1 + # Save the image with the determined filename + img.save(filename, format="PNG") + # Prepare metadata metadata = PngInfo() if prompt is not None: @@ -48,13 +52,12 @@ class SaveApiImage: for k, v in extra_pnginfo.items(): metadata.add_text(k, json.dumps(v)) - # Save the image with the determined filename and metadata - img.save(filename, format="PNG", pnginfo=metadata) - - # Write the number of the last image to a text file with leading zeroes - with open("./output/api_next_image.txt", "w") as f: - f.write(f"api_{counter+1:05d}.png") - + # Update the symbolic link in the output directory + link_path = "./output/BJORNULF_API_LAST_IMAGE.png" + if os.path.exists(link_path): + os.remove(link_path) + os.symlink(os.path.abspath(filename), link_path) + print(f"Image saved as: {filename}") return {"ui": {"images": [{"filename": filename, "type": "output"}]}} \ No newline at end of file diff --git a/screenshots/save_api.png b/screenshots/save_api.png deleted file mode 100644 index 7f436f6..0000000 Binary files a/screenshots/save_api.png and /dev/null differ diff --git a/screenshots/save_bjornulf_lobechat.png b/screenshots/save_bjornulf_lobechat.png new file mode 100644 index 0000000..5f72151 Binary files /dev/null and b/screenshots/save_bjornulf_lobechat.png differ