Nodes/ComfyUI-FairLab/Image To Base64
ComfyUI Node

Image To Base64

Ship a PNG as text — Image To Base64 encodes your render for APIs and JSON

By yanhuifair·Created 2 years ago·Updated 3 months ago· 2
Image To Base64
  • image
  • string

Every API that accepts images ends up asking for them one of two ways: a file, or a base64 string. If your workflow needs to hand an image to an external service, a webhook, or a JSON payload, this node is the fileless route - it takes an image tensor, encodes it as a base64 PNG string, and hands that string to anything downstream that wants text.

The mechanism is a two-step encode, visible in the source: the image tensor is converted to a PIL image, saved to an in-memory buffer as PNG, and the bytes are base64-encoded into a string. One detail worth knowing: by default the output is the bare base64 payload - no data:image/png;base64, prefix. That matters because some APIs want the prefixed data-URI form and some want the raw string. The pack's own encoder has a header parameter that adds the prefix, but this node's public interface doesn't expose it, so the output is raw base64. If your target API demands the prefix, you'll need to prepend it yourself, or use the pack's Base64 To Image node on the round trip and remember it accepts both forms on the way in.

The input:

  • image - the image to encode.

The output:

  • string - the base64-encoded PNG.

Where it fits: API-integration workflows are the honest answer - the KB's image-I/O doc is all about ComfyUI treating images as files with embedded metadata, and base64 is the fileless counterpoint. Send a render to an image-captioning API, embed a preview in a JSON document, or pass an image to an LLM vision endpoint that accepts base64 input. Because the output is a plain string, you can also log it, inspect it, or route it through any string plumbing before it leaves the graph.

Honest notes: a 1024×1024 PNG as base64 is roughly a megabyte and a half of text - fine for local processing, slow and heavy if you're serializing hundreds of images. And because the encode goes through PNG, any metadata that was in the original tensor's image data (as opposed to saved-file chunks) doesn't survive as structured metadata - this is about pixels as text, not about preserving the workflow. If you need the workflow embedded, save to a PNG file instead.

Install is the standard pack path: ComfyUI Manager → search ComfyUI-FairLab → install → restart:

cd ComfyUI/custom_nodes
git clone https://github.com/yanhuifair/ComfyUI-FairLab.git
cd ComfyUI-FairLab
pip install -r requirements.txt

Restart, search "Image To Base64" or "base64 encode". No models, no network, no dependencies beyond the pack - PIL encode only.

CategoryFair/image

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (1)

NameTypeDescription
stringSTRING