46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
|
|
from server import PromptServer
|
|
from PIL import Image, ImageOps
|
|
import numpy as np
|
|
|
|
from server import PromptServer, BinaryEventTypes
|
|
|
|
class SendImageWebSocketNode:
|
|
@classmethod
|
|
def INPUT_TYPES(s):
|
|
return {"required": {"images": ("IMAGE",)}}
|
|
|
|
RETURN_TYPES = ()
|
|
FUNCTION = "send_images"
|
|
OUTPUT_NODE = True
|
|
CATEGORY = "Easy Nodes"
|
|
|
|
def send_images(self, images):
|
|
results = []
|
|
for tensor in images:
|
|
array = 255.0 * tensor.cpu().numpy()
|
|
image = Image.fromarray(np.clip(array, 0, 255).astype(np.uint8))
|
|
|
|
server = PromptServer.instance
|
|
server.send_sync(
|
|
BinaryEventTypes.UNENCODED_PREVIEW_IMAGE,
|
|
["PNG", image, None],
|
|
server.client_id,
|
|
)
|
|
results.append(
|
|
# Could put some kind of ID here, but for now just match them by index
|
|
{"source": "websocket", "content-type": "image/png", "type": "output"}
|
|
)
|
|
|
|
return {"ui": {"images": results}}
|
|
|
|
|
|
|
|
NODE_CLASS_MAPPINGS = {
|
|
"SendImageWebSocket": SendImageWebSocketNode
|
|
}
|
|
|
|
# A dictionary that contains the friendly/humanly readable titles for the nodes
|
|
NODE_DISPLAY_NAME_MAPPINGS = {
|
|
"SendImageWebSocketNode": "Send base64 encoded image WebSocket"
|
|
} |