Nodes/comfyui-easyapi-nodes/Mask Image To Base64
ComfyUI Node

Mask Image To Base64

Send a mask that's already an image out as base64

By lldacing·Created 3 years ago·Updated 8 months ago· 96
Mask Image To Base64
  • images
  • base64Images

This node is the sibling of MaskToBase64Image, and the two are easy to grab confused - the difference is entirely in what type goes in. MaskToBase64Image takes ComfyUI's native MASK type. MaskImageToBase64 takes an IMAGE - specifically, a mask that's already been rendered as a visual image (say, a mask preview you built elsewhere in the graph, or output from a node that converts masks to images) - and base64-encodes that instead.

How it works

It's a plain image-to-base64 conversion under the hood, same as the rest of this pack's base64 nodes, but tagged so the consumer knows what they're looking at: the pack's own README describes it as producing base64 with imageType=["mask"]. It's also marked as an output node, meaning the result rides straight out in the run's websocket message under base64Images (with a matching base64Type) - the same channel ComfyUI's API uses to hand results back to a caller - without you needing a separate save or preview step.

The inputs and outputs that matter

  • images (IMAGE) - the mask, already rendered as a normal image.
  • base64Images (STRING) - the encoded output, tagged as mask-type.

Why this exists as a separate node at all

It'd be reasonable to assume "convert a mask to base64" only ever needs one node. The reason there are two is that ComfyUI's graph genuinely produces masks in both shapes depending on where they came from - a mask visualized by something like a preview or compositing node is an IMAGE, while a mask straight out of SAM, an alpha extraction, or a paint widget is the native MASK type. Rather than silently coercing one into the other (and getting the channel semantics wrong), this pack keeps the two paths explicit and lets the type system catch the mistake for you.

How to install it

Via ComfyUI Manager: search comfyui-easyapi-nodes, install, restart. Manually:

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 models needed.

Common issues & troubleshooting

Wire a MASK straight in and you'll get a type error. That's your sign you actually want MaskToBase64Image instead - it accepts native MASK and does the image conversion for you internally, rather than expecting you to have converted it already.

Watch memory on long-running instances. Every base64 node in this pack shares the same caveat from the README: the strings sit in ComfyUI's execution history in memory, and the default history cap is 10,000 entries. If you're calling this node regularly, turn that down under Settings → [EasyApi] Maximum History Size rather than letting base64 payloads accumulate unnoticed.

CategoryEasyApi/Image

Inputs (1)

NameTypeDefaultDescription
imagesIMAGE

Outputs (1)

NameTypeDescription
base64ImagesSTRING