Load Images (Base64)
Batch-load images into ComfyUI from one packed base64 string
- IMAGE
- MASK
This is the sibling of Knodes' Load Image (Base64), but for batches - and it comes with a twist. Instead of accepting a list of base64 strings, it takes one string that packs several images together using a compact hex framing. If you're moving one image at a time, use the single loader. If you're shipping a whole batch over a wire in a single round trip, this is the node.
The framing protocol (this is the part to get right)
The single strings input has to follow a fixed layout, straight from the author's README:
0x4(Image count) 0x8(Image1 length) Image1(base64) ... 0x8(ImageN length) ImageN(base64)
- First 4 hex characters = how many images are packed in.
- Then, repeated for each image: 8 hex characters giving the length (in characters) of the following base64 blob, followed by that many base64 characters.
So a payload with two images starts with 0002, then 0000000c (12 chars) followed by 12 base64 chars for the first image, then another 8-hex length and the second blob. The parser strips leading zeros and reads the lengths as hex, so the fixed-width form (0002, not 2) is the safe thing to send.
Outputs and how they behave
- IMAGE - a genuine batch, built with
torch.cat, shaped[N, H, W, 3]. A real batch opens the door to batched KSampler runs instead of looping one image at a time. - MASK - one mask per image, also concatenated. Alpha channels become
1 - alphamasks exactly like ComfyUI's core loader; images without alpha get the empty 64×64 mask.
Where it earns its keep
It's a transport node, so its value shows up on the integration side: a frontend that already encodes images to base64 and wants to move N of them in one message instead of N messages, or a constrained sender that can handle a long string but not a JSON array. Combined with the pack's Image(s) To Websocket (Base64) output node you get a complete string-only round trip between your app and the graph.
The gotchas
- Every image must be the same resolution. The batch is
torch.cat'd, and mixing sizes throws a shape mismatch. Your sender has to normalize. - Masks get cat'ed too, which is the subtler trap: if some images have alpha and others don't, the real-sized mask from the PNGs collides with the 64×64 empty mask and the node errors. Keep your input uniform - all PNG-with-alpha or all alpha-less.
- It's not human-readable. This is a hand-rolled framing format, so both ends have to agree on it exactly. If you control the sender, fine; if you're debugging, hex lengths are easier to verify than they look.
Installing Knodes
Same story as the rest of the pack: no requirements.txt, no models, nothing but PIL, numpy and torch that ComfyUI already has. Via ComfyUI Manager, search "Knodes"; or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/kft334/Knodes
Restart and you're done. Just remember that this node only pays off when you're actually moving batches - for a single image the non-batch loader is simpler and less to keep in sync.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| strings | STRING | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |