Image to PNG Data URI
Turn an Image Into a Single Giant Base64 String
- image
- data_uri
- base64_string
Every once in a while you need an image as a string. Not a path, not a tensor - an actual text blob you can paste into an API call, stuff into a prompt for a vision model, or embed in a document. That's this node's entire reason to exist: take a ComfyUI IMAGE tensor and hand you back a data:image/png;base64,... URI ready to drop wherever a data URI is accepted.
How it works
The conversion is textbook: it takes the first image in the batch, converts the tensor back to uint8 pixels, encodes it as PNG into a byte buffer, base64-encodes those bytes, and prefixes data:image/png;base64,. The mechanism detail worth knowing is that it saves the PNG with compress_level=0 - that's the "fastest, largest" compression setting. You get a bigger string than a compressed PNG would give, but it encodes instantly, which matters when you're feeding a sequence of frames through a vision pipeline and don't want each one to spend half a second squeezing bytes.
Input and output
image(IMAGE) - any ComfyUI image tensor. Note it takes the first frame of the batch; if you feed it a 128-frame video it quietly encodes frame 0.- Output:
data_uri(STRING) - thedata:image/png;base64,...string.
(The underlying class also builds the raw base64 payload without the prefix, but the exposed output you'll wire up is the full data URI.)
Install
Pack standard: ComfyUI Manager → "Sagado Nodes for ComfyUI", or
cd ComfyUI/custom_nodes
git clone https://github.com/5agado/ComfyUI-Sagado-Nodes
pip install -r ComfyUI-Sagado-Nodes/requirements.txt
Restart. Needs pillow and numpy, both in the pack's requirements - no models.
Where it actually shines
The most natural pairing is the pack's own LLM nodes: when you're running a vision model that wants the image inline rather than as a file, encode here and pass the string where image_base64 is expected. It also slots into any API wrapper that takes a data URI. Expect the string to be long - a 1024×1024 PNG base64-encoded is easily a couple of megabytes of text, which is why these strings live inside API payloads and not in files. If you only need the base64 without the data: prefix for some endpoint, strip the first 22 characters. And if you're worried about the uncompressed size, remember the compress_level=0 tradeoff - it's the speed/size bargain this node made for you.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| data_uri | STRING | — |
| base64_string | STRING | — |