Load Img From Base64
Paste an Image Into ComfyUI as Plain Text
- image
- mask
- width
- height
The stock LoadImage node has a hard requirement nobody mentions until it bites you: the image has to already exist on the ComfyUI machine's disk. That's fine when you're dragging files around your own desktop. It's a wall when your image lives in a browser tab, a phone, or an external script. That's exactly the problem this node exists to solve - it lets you inline an image as a base64 string and have ComfyUI decode it into a real, usable tensor.
Despite the "Base64 To Image" name, there's no API call here, no key, no fetch. The whole thing is base64.b64decode plus cv2.imdecode in a single node. That's the whole trick, and it's exactly why it's reliable.
How it works
You get one input: data, a STRING (default empty). Paste a base64-encoded image into it - or wire it in from a text node if your string is being generated somewhere else. Hit run and the node strips newlines and whitespace, pads the string correctly, decodes it to bytes, and runs cv2.imdecode with IMREAD_UNCHANGED, which is the flag that keeps the alpha channel alive.
Then the interesting part: it splits the 4th channel (alpha) out as a 0–1 float mask, converts BGR(A)→RGB, normalizes to 0–1, and adds the batch dimension - so the image output is format-identical to what core LoadImage gives you. If your base64 has no alpha, you get a solid all-ones mask (fully opaque), which is also what core does.
The README calls the input a "data URI," but here's the trap: this node does not strip a data:image/png;base64, prefix. Feed it the bare base64 string. If you include the prefix, base64.b64decode throws an "Incorrect padding" error. The README's own example is just the bare string - follow that.
The outputs that matter
Four outputs, three of which you'll actually use:
image(IMAGE) - wires straight intoVAEEncode, a ControlNet preprocessor, IPAdapter, anything that takes an image.mask(MASK) - feed it toSetLatentNoiseMaskfor inpainting. Transparent PNGs come through as real masks.width/height(INT) - the decoded pixel dimensions.
Those last two are the entire reason this fork exists. The upstream pack it's based on (glowcone's comfyui-base64-to-image) drops the image and mask and leaves you guessing the resolution. Here you can wire width and height straight into EmptyLatentImage and skip a separate "Get Image Size" node.
Installing it
ComfyUI Manager - search "comfyui-base64-to-image-size" and click install. Or the old-fashioned way:
cd ComfyUI/custom_nodes
git clone https://github.com/Sayene/comfyui-base64-to-image-size
Then restart ComfyUI. The good news: there are no model downloads and no extra pip dependencies to fight with. The node imports cv2, numpy, and torch, all of which ComfyUI already ships (opencv-python-headless is a core dependency), so this is a genuinely dependency-light custom node - one of the easy ones.
Troubleshooting
- "Incorrect padding" error - you pasted the
data:prefix, or mangled the string. Bare base64 only. Newlines and spaces are handled automatically, so multi-line pastes are fine. - A crash around
result.shape-cv2.imdecodereturnedNone, which means the string wasn't a decodable image at all. Double-check you copied the whole thing. - A "Received base64 data hash" line in the console - that's normal; the node logs a sha256 of your input on every run. Ignore it.
- Your mask is all white for a PNG with transparency - the source only pulls the alpha channel when the image has 4 channels. If your encoder flattened it to RGB first, there's no alpha to find.
One honest caveat: for a single image, dragging it into ComfyUI is faster than encoding it. This node earns its keep when you're automating - building a script or service that POSTs workflows to ComfyUI's API with images inline in the JSON payload. And if you do stand up an API like that, remember the ecosystem's standing advice: the ComfyUI API is unauthenticated by default, so don't expose it to the internet without a reverse proxy or auth in front of it.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| data | STRING | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | The loaded image tensor. |
| mask | MASK | The alpha mask tensor. |
| width | INT | The width of the image. |
| height | INT | The height of the image. |