From 6a9bd063db11ed2e8cd0375ab228b4f562e4b37d Mon Sep 17 00:00:00 2001 From: kft334 <93904307+kft334@users.noreply.github.com> Date: Thu, 4 Jan 2024 21:02:12 -0500 Subject: [PATCH] Add files via upload --- Knodes.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ __init__.py | 4 ++++ 2 files changed, 51 insertions(+) create mode 100644 Knodes.py create mode 100644 __init__.py diff --git a/Knodes.py b/Knodes.py new file mode 100644 index 0000000..b5b397d --- /dev/null +++ b/Knodes.py @@ -0,0 +1,47 @@ +from server import PromptServer +from io import BytesIO +from PIL import Image +import numpy as np +import base64 + +class ImageOutput: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "images": ("IMAGE", {"default": None, "forceInput": True}), + "text": ("STRING", {"default": None})} + } + + RETURN_TYPES = ("IMAGE",) + RETURN_NAMES = ("IMAGE",) + + FUNCTION = "Proc" + + OUTPUT_NODE = True + + CATEGORY = "Knodes" + + def Proc(self, images, text = ""): + outs = [] + for single_image in images: + img = np.asarray(single_image * 255., dtype=np.uint8) + img = Image.fromarray(img) + buffered = BytesIO() + img.save(buffered, format="PNG") + img_str = base64.b64encode(buffered.getvalue()).decode() + outs.append(img_str) + + PromptServer.instance.send_sync("knodes", {"images": outs, "text": text}) + return images + +NODE_CLASS_MAPPINGS = { + "Image(s) To Websocket (Base64)": ImageOutput +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "ImageOutput": "Image(s) To Websocket (Base64)" +} diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..61e3cf4 --- /dev/null +++ b/__init__.py @@ -0,0 +1,4 @@ +from .Knodes import ImageOutput +NODE_CLASS_MAPPINGS = {"ImageOutput": ImageOutput} +NODE_DISPLAY_NAME_MAPPINGS = {"ImageOutput": "Image(s) To Websocket (Base64)"} +__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS'] \ No newline at end of file