Nodes/ComfyUI-MultiCutAndDrag/LoadImagesFromBase64Array
ComfyUI Node

LoadImagesFromBase64Array

Hand ComfyUI a batch of images from a script — no temp files, no disk

By Pablerdo·Created about a year ago·Updated about a year ago· 4
LoadImagesFromBase64Array
    • IMAGE
    • MASK
    data_array[]

    Here's the workflow that makes this node worth knowing: your script computes masks or frames outside ComfyUI - a segmentation pass, some pre-rendered animation plates - and you need them inside the graph without dumping a dozen temp PNGs somewhere and loading them with a filesystem node. LoadImagesFromBase64Array is the door for that. It takes a JSON array of base64-encoded images, decodes them all, and hands you a batched IMAGE plus a MASK. It's the array-flavored sibling of LoadImageFromBase64 in the same pack (the original is credited to glowcone).

    The use case is automation: you're driving ComfyUI from code, or your masks genuinely live in memory (the base64 output of an API, a generated alpha channel) rather than on disk. Feed it a JSON string, get a tensor. Clean.

    How it works

    Simple and honest. The data_array string is parsed with json.loads - it must be a JSON array. Each element is base64-decoded and run through OpenCV's cv2.imdecode with IMREAD_UNCHANGED, so alpha survives. If a decoded image has four or more channels, the alpha channel becomes that image's mask, normalized to 0–1; if there's no alpha (like JPEG), the mask is a ones-tensor the size of the image. Everything is converted from BGR/BGRA to RGB and stacked into one batch on output.

    Inputs and outputs

    Just one input: data_array, a STRING defaulting to "[]". It expects JSON in this shape:

    ["iVBORw0KGgoAAAANSUhEUgAA...", "iVBORw0KGgoAAAANSUhEUgAA..."]
    

    Outputs are two batched tensors: IMAGE (the decoded images) and MASK (per-image alpha, or all-ones where there's no alpha). In this pack's context, that IMAGE feeds MultiCutAndDragOnPath, and the MASK output is a handy free bonus when your source PNGs already carry alpha.

    Installation

    Part of ComfyUI-MultiCutAndDrag:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Pablerdo/ComfyUI-MultiCutAndDrag
    

    Restart ComfyUI, or install "MultiCutAndDrag" via ComfyUI Manager. It pulls opencv-python (used for the actual decoding) plus the pack's other deps. No model files, nothing to download beyond the package.

    Common issues

    • No data-URI prefixes. The node calls base64.b64decode directly, so a data:image/png;base64,... string blows up. Strip the prefix and the mime type; pass the bare base64.
    • Don't leave it at "[]". An empty array reaches torch.cat on an empty list and errors out. Always pass a real list, even a single-element one.
    • JPEGs give you a full-white mask (no alpha), which is correct behavior but easy to misread as a bug if you were expecting a cutout.
    • Mask values come back normalized to 0–1, matching how the rest of the pack expects them.

    It's a niche node with a narrow job, and it does that job without ceremony. If you've ever fought ComfyUI to accept data that isn't a file, this is the shortest path to ending that fight.

    CategoryPSNodes/image

    Inputs (1)

    NameTypeDefaultDescription
    data_arraySTRING[]

    Outputs (2)

    NameTypeDescription
    IMAGEIMAGE
    MASKMASK