Nodes/Painting Coder Utils/Image To Base64 🎨
ComfyUI Node

Image To Base64 🎨

Turn any image into a data URI — for the APIs and tools that want one

By jammyfu·Created 2 years ago·Updated about a year ago· 16
Image To Base64 🎨
  • images
  • base64_images
add_data_uritrue

Plenty of things want an image as a big base64 string instead of a file - an API endpoint, an HTML email, a JSON payload, a Python script you're feeding from inside ComfyUI. Image To Base64 is the node that performs that conversion: any IMAGE that crosses its input leaves as a base64-encoded PNG string (or a list of them), ready to paste anywhere.

It's part of the Painting Coder Utils pack and it's the natural companion to the pack's Web Image Loader 🌐, which goes the other direction (base64 or URL back into an IMAGE).

How it works

The node takes the images tensor, converts each image to a PIL image, saves it as PNG into an in-memory buffer, and base64-encodes the bytes. A single add_data_uri boolean (default on) controls whether the output gets the data:image/png;base64, prefix - the data-URI form that most web APIs and HTML embeds expect. Turn it off and you get the raw base64 payload if the consumer wants to do its own prefixing.

Two behaviors worth knowing:

  • Single image in, single string out. If your input has a batch dimension of one, you get one string back. A batch returns a list of strings.
  • Errors degrade to empty. If something fails mid-conversion, it returns an empty string rather than crashing the graph. Fine for keeping the workflow alive, but an empty string downstream usually means "check your input."

Inputs and output

  • images - the IMAGE tensor(s) to encode.
  • add_data_uri - include the data:image/png;base64, prefix (default true).
  • Output: base64_images - the encoded string(s).

Where you'll use it

  • Feeding APIs and web services that take images as data URIs - vision models, image analysis endpoints, embedding images in HTML or JSON.
  • Custom nodes and script bridges - your own Python nodes can grab this output and do whatever they need with a self-contained image payload.
  • Transport - base64 is awkward to read but trivial to move around, so it's a decent staging format between steps.

The catch is the same one that applies to any base64 workflow: it's bulky. A 1024×1024 PNG can be a megabyte-plus of base64 text, and it lives as a string in your graph. Fine for a couple of images, silly for fifty. Also note it's PNG-encoded specifically - no JPEG size knob, so don't reach for this when storage size is the concern.

Install

ComfyUI Manager → Painting Coder Utils, or:

cd ComfyUI/custom_nodes
git clone https://github.com/jammyfu/ComfyUI_PaintingCoderUtils.git

Restart ComfyUI. No models or API keys anywhere in the pack; its dependencies (numpy, Pillow, torch, gradio) are already present in a stock ComfyUI. The usual pack caveat applies if you're loading inherited workflows: v0.3.0 renamed the namespace, and docs/fix/workflow_fixer.html repairs old JSON.

Category🎨Painting👓Coder/🖼️Image

Inputs (2)

NameTypeDefaultDescription
imagesIMAGE
add_data_urioptBOOLEANtrue

Outputs (1)

NameTypeDescription
base64_imagesSTRING