Nodes/Knodes/Image(s) To Websocket (Base64)
ComfyUI Node

Image(s) To Websocket (Base64)

Push ComfyUI's output to your own web app over the websocket

By kft334·Created 3 years ago·Updated 2 years ago· 4
Image(s) To Websocket (Base64)
  • images
  • IMAGE
Actions

You're probably not the usual visitor here. Most ComfyUI users run a graph, look at the preview, and fish PNGs out of the output folder. You're the one who built a web app around ComfyUI - a custom frontend, an automation dashboard, a pipeline that calls the API - and you want the finished image delivered straight to your code, not written to disk. That's what this node does. It takes whatever image batch it's fed, base64-encodes every frame, and pushes them over the websocket to whoever is listening.

What it actually does

ImageOutput (display name "Image(s) To Websocket (Base64)") is one of three nodes in the small kft334/Knodes pack, and it's the flagship of the set. For each image in the input batch it converts the tensor to a PNG, base64-encodes it, and calls PromptServer.instance.send_sync("knodes", {...}) - the exact same websocket ComfyUI's own frontend already uses. On the receiving end, your code listens for a message whose type is "knodes" and reads data.images (a list of base64 strings, one per image) and data.Actions.

The node's output port is a passthrough: it returns the batch you fed in, unchanged. Wire it to a core Save Image if you also want a copy on disk, or leave it dangling - the real payload already left via the websocket. Since the node is marked as an output node, the workflow counts as finished when it fires, which makes it a clean terminal step.

The two inputs that matter

  • images (IMAGE) - the batch to ship. It's flagged forceInput, so you can't pick a file; you must wire it from whatever produces your image, be that a VAE Decode, an upscaler, or a batch of video frames.
  • Actions (STRING) - a free-text string that rides along in the websocket payload. Think of it as a routing tag: drop "portrait" or "batch-3" in there and your frontend can decide what to do with each delivery. It's technically required but defaults to empty, so you can ignore it.

Wiring it into a workflow

The classic setup is an API-driven workflow: your frontend POSTs the graph to /prompt, and this node sits at the end. Your listener connects to the same socket (ws://127.0.0.1:8188/ws?clientId=...), matches the knodes message type, and decodes the base64 in data.images. On the JS side that's about three lines.

Installing Knodes

This is the easy part. The pack ships no requirements.txt - it only touches PIL, numpy, torch and base64, all of which already live inside ComfyUI. Install via ComfyUI Manager (search "Knodes") or by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/kft334/Knodes

Restart ComfyUI. No pip install, no model downloads, nothing.

Gotchas worth knowing

If nothing is listening on the websocket, the message just evaporates - the node still returns the images and the workflow completes without complaint, so a missing listener is silent rather than loud. And be honest about whether you need this at all: if the only consumer is ComfyUI's own UI, core Save Image does the job with less plumbing. This node earns its keep only when images need to travel to code you wrote. It's a tiny, barely-known pack from early 2024, but the mechanism is plain and it does one job cleanly.

CategoryKnodes

Inputs (2)

NameTypeDefaultDescription
imagesIMAGE
ActionsSTRING

Outputs (1)

NameTypeDescription
IMAGEIMAGE