Add files via upload

This commit is contained in:
kft334
2024-01-04 21:02:12 -05:00
committed by GitHub
parent 5630bbef53
commit 6a9bd063db
2 changed files with 51 additions and 0 deletions
+47
View File
@@ -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)"
}
+4
View File
@@ -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']