ComfyUI Node

Image Batch

A ComfyUI node in Zuellni/Image with 1 input and 2 outputs.

By Zuellni·Created 3 years ago·Updated 3 years ago· 43
Image Batch
    • IMAGES
    • MASKS
    input_dir/tmp/ComfyUI/input

    Sometimes the images you want to work with aren't in your ComfyUI graph yet - they're sitting in a folder. Image Batch loads every image in a directory as a single batch tensor, GIFs included (it explodes animated GIFs into their frames). If you've ever wanted to img2img a whole folder, upscale a set of frames, or feed an animation's frames into a batch-aware node, this is the simplest way to get there.

    What it is

    One input, one job: point input_dir at a folder, and it globs bmp, gif, jpeg, jpg, png, and webp files, loads them all, and returns IMAGES plus a MASKS output. It's the file-facing mirror of the pack's Image Saver, and the two together make a tidy "process a folder without leaving the graph" workflow.

    The alpha-channel trick

    Here's the part most people don't expect: the MASKS output is the alpha channel of your images. Transparent PNGs get their transparency separated out as a mask (pixels with zero alpha are zeroed in the RGB data), which is genuinely handy for compositing work - you get the image and its cutout mask in one pass, perfectly aligned. If your images have no alpha, the masks output is solid white.

    The dimension normalization, and why it matters

    Images of different sizes can't share a batch tensor, so the node forces everything to one size: it resizes all images to the smallest dimensions found in the batch, snapped to multiples of 8, then center-crops the rest to match. This is a real behavior, not a corner case - load a folder with mixed sizes and the output is uniformly small.

    That's usually what you want (a batch for a sampler needs equal dimensions), but it has two consequences worth knowing:

    • Order isn't guaranteed. The code globs the directory without sorting, so don't rely on file order for frame sequences. If frame order matters (e.g. you're loading an animation's stills), sort your filenames yourself or load frames in the order you need.
    • GIFs explode. An animated GIF with 30 frames becomes 30 batch entries. A folder of GIFs can silently balloon into a huge batch - check your VRAM before you run a sampler over it.

    What it doesn't do

    It's a loader, not a processor. There's no filtering, no sorting, no per-file options. If the folder has no readable images, the node just interrupts the run (you'll see the graph halt). For anything more structured, you'd be reaching for something like WAS Node Suite or VHS - this node is deliberately minimal.

    Install

    Part of Zuellni/ComfyUI-Custom-Nodes. Via ComfyUI Manager (search "Zuellni") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Zuellni/ComfyUI-Custom-Nodes
    

    Restart ComfyUI. This node needs only Pillow and torch, which ComfyUI already ships - no extra requirements, no model downloads. It's one of the lightest nodes in the pack, and one of the least likely to rot: the pack is archived, but this is simple code over stable libraries, so it keeps working.

    The default input_dir points at ComfyUI's own input folder, which is convenient but means "browse" workflows want you to drop files there. You can type any absolute path instead - including a folder full of exports from another tool.

    CategoryZuellni/Image

    Inputs (1)

    NameTypeDefaultDescription
    input_dirSTRING/tmp/ComfyUI/input

    Outputs (2)

    NameTypeDescription
    IMAGESIMAGE
    MASKSMASK