Nodes/comfyui-easyapi-nodes/Image To Base64 (Advanced)
ComfyUI Node

Image To Base64 (Advanced)

Base64 output that also tags image vs mask

By lldacing·Created 3 years ago·Updated 8 months ago· 96
Image To Base64 (Advanced)
  • images
  • base64Images
imageTypeimage

This is the plain ImageToBase64 node plus one extra dial: a type tag that tells your API caller whether the base64 string it's getting back represents an ordinary image or a mask. Everything else works the same - encode an IMAGE to a base64 string, skip the round-trip through disk entirely, get the bytes straight back in the run's response.

Why that tag matters: if your workflow returns several base64 outputs in one response - say, a generated image and the mask that was used to make it - the caller on the other end needs some way to tell which blob is which without guessing from context. imageType is that flag. It's part of comfyui-easyapi-nodes, lldacing's pack aimed at people driving ComfyUI as an API backend, and per the pack's own README, this metadata is specifically there "to make it convenient for the API caller to distinguish" - that's the entire design rationale for the node existing separately from the plain version.

How it works

Same encoding path as ImageToBase64 - it's an output node, so it registers as a real result of the run and attaches the encoded string to the response under base64Images, no file written to disk. The only difference is the imageType value gets attached alongside the base64 string in that same message data, so a client parsing the response knows how to interpret what it received.

The inputs and outputs that matter

  • images (IMAGE, required) - the image or batch to encode.
  • imageType (enum, default "image", choices image / mask) - the label attached to the encoded output. Set it to mask when you're actually sending a mask through this node so the caller doesn't mistake it for a regular image.
  • Output: base64Images (STRING) - the encoded string, same as the plain node.

If you don't need to distinguish image from mask in your response - say, your workflow only ever returns one kind of thing - the plain ImageToBase64 node does the same job with one less input to think about.

How to install it

Through ComfyUI Manager, searching comfyui-easyapi-nodes. Manual install:

cd ComfyUI/custom_nodes
git clone https://github.com/lldacing/comfyui-easyapi-nodes.git
cd comfyui-easyapi-nodes
pip install -r requirements.txt

Restart ComfyUI. No model downloads - encoding is CPU work, no GPU dependency of its own.

Common issues & troubleshooting

Response is huge / UI feels sluggish. Same tradeoff as the plain ImageToBase64 node - base64 strings run noticeably longer than the binary they encode, and the pack's own README flags this directly, suggesting object storage plus a URL-based load node for production-scale traffic instead of base64 everywhere. The "Maximum History Size" setting under Settings → EasyApi exists specifically because keeping many base64-heavy runs in memory can add up.

imageType doesn't seem to change the actual image data. It shouldn't - it's metadata attached alongside the encoding, not a processing step. Setting it to mask doesn't convert an IMAGE into a MASK type or alter the pixels; it just tags what the caller should interpret the bytes as.

I fed it an actual MASK-typed input and it didn't accept it. The images input is typed IMAGE, not MASK - if you're encoding an actual mask, convert it to an image representation first (or check whether the mask you're working with already has an IMAGE-typed counterpart elsewhere in your graph) before wiring it in here.

CategoryEasyApi/Image

Inputs (2)

NameTypeDefaultDescription
imagesIMAGE
imageTypeCOMBOimage2 options: image, mask

Outputs (1)

NameTypeDescription
base64ImagesSTRING