Nodes/ComfyUI-Prompt-Helper/Load Image Batch (dir)
ComfyUI Node

Load Image Batch (dir)

Turn a folder into a batch in one node

By Elypha·Created 2 years ago·Updated 12 months ago· 0
Load Image Batch (dir)
    • IMAGE
    • MASK
    • COUNT
    • FILENAMES
    directory
    skips0
    sort_by
    trim_suffixfalse
    recursivefalse

    Core ComfyUI's Load Image takes one file. This node takes a whole folder and hands you one IMAGE batch. Point it at a directory of PNGs, and it loads every image, stacks them into a single batched tensor, and also hands you the masks, the count, and the filenames. It's the foundation node for anything that processes a folder full of images - img2img sweeps, batch face-fixing, contact sheets, dataset prep.

    The mechanism, straight from the source: the node globs the directory (or recurses through subfolders if recursive is on) for .jpg, .jpeg, .png, and .webp files, sorts them, and loads each with the same decode core ComfyUI's Load Image uses - EXIF orientation respected, converted to RGB, normalized to a 0–1 float tensor. Each image's alpha channel becomes its MASK output (solid white where there's no alpha). Then everything is concatenated into one tensor with shape (N, H, W, 3).

    That concatenation is the whole design, and it's where the constraint lives: all images must have the same dimensions. The node enforces it with a hard error that names the offending file, because you can't stack a 512×512 next to a 1024×1024 into one tensor. If your folder is mixed-size, this is the wrong node - Load Image List (dir) in the same pack handles per-image tensors instead.

    The inputs that matter

    • directory - absolute path to the folder
    • sort_by - the ordering that determines batch order: none, text asc/desc, number asc/desc (it grabs the first number in each filename - great for frame_001.png sequences), or file modification time. With skips you can then drop N images off the front, which is how you'd skip a first frame or a thumbnail set.
    • recursive / trim_suffix - recurse into subfolders, and strip file extensions from the FILENAMES output

    Outputs: IMAGE (the batch), MASK, COUNT (how many loaded), and FILENAMES (matching the sort order - wire them into the saver on the far side if you want round-tripping filenames).

    Installing it

    No dependencies beyond ComfyUI's own, no models. ComfyUI Manager → ComfyUI-Prompt-Helper, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/elypha/ComfyUI-Prompt-Helper
    

    Restart. It's in the image category.

    The failure modes you'll actually hit

    Two, both self-inflicted. The mixed-dimension error above - fix it by pre-resizing your folder. And the "no image files found" error, which fires when the path is wrong or the folder's empty - it's explicit about it. Get past those and this node is the boring, dependable backbone of a lot of batch workflows.

    Categoryimage

    Inputs (5)

    NameTypeDefaultDescription
    directorySTRING
    skipsoptINT00–9223372036854776000
    sort_byoptCOMBO7 options: None, As Text (Asc), As Text (Desc), As Number (Asc), As Number (Desc), Time Modified (ASC), +1
    trim_suffixoptBOOLEANfalseIf enabled, FILENAMES output will have the file suffix removed.
    recursiveoptBOOLEANfalseIf enabled, the directory will be searched recursively.

    Outputs (4)

    NameTypeDescription
    IMAGEIMAGE
    MASKMASK
    COUNTINT
    FILENAMESSTRING