Nodes/ComfyCollectorNodes/Image Loader By Index (CCN)
ComfyUI Node

Image Loader By Index (CCN)

Load the Nth image in a folder, no file picker needed

By valkymaera·Created 4 months ago·Updated 10 days ago· 1
Image Loader By Index (CCN)
    • image
    • mask
    • filename
    • file_path
    • total_files
    • actual_index
    • wrapped
    directory
    recursivefalse
    index0
    debugfalse

    The standard Load Image node makes you pick a file from a dropdown, which is great for humans and useless for automation. Image Loader By Index is the automation version: you point it at a folder, give it a number, and it loads the Nth image in that folder. Feed the index from a counter, a seed, or anything that changes per run, and you've got an image-by-index batch machine with zero clicking.

    The node reads a directory (an absolute path - this isn't the ComfyUI input-folder picker, you type the path), lists the supported image files, sorts them alphabetically, and loads the one at index. Turn on recursive and it walks subfolders, with relative paths used for the sort order. A debug toggle prints which image it chose and why.

    The outputs that make it feel like a tool

    This is where the node earns its keep, because it doesn't just hand you an image:

    • image - the loaded frame, straight into whatever needs it.
    • mask - the alpha channel as a mask when the file is RGBA (empty otherwise), so transparent refs don't lose their cutout.
    • filename and file_path - what it actually loaded, for logging or downstream filename work.
    • total_files and actual_index - how many files were found and which one you got.
    • wrapped - a boolean that's true when your index went past the end and wrapped around.

    That wrapped flag is the quietly clever bit. Index out of range? It doesn't error - it wraps via modulo and tells you. So a sweep that runs more iterations than you have images degrades gracefully instead of killing the queue. Wire wrapped into a stop condition or a UI display and you can build a proper "all images processed, stop here" loop.

    Where people actually use it

    The author built it for iterating reference images in I2V and img2img workflows - the classic pattern is feeding each frame or reference through one at a time while the rest of the graph stays put. Pair the index with a Gated Increment (also from this pack) set to step the index, or drive it off a seed node's randomize, and a folder of refs becomes a batch source. Sorting is alphabetical, so name files with zero-padded numbers (ref_01.png, ref_02.png…) or your "index 3" won't be the third image you think it is - that's the one real footgun here.

    Install

    It ships in ComfyCollectorNodes:

    cd ComfyUI/custom_nodes
    git clone https://github.com/valkymaera/ComfyCollectorNodes
    

    restart, or ComfyUI Manager → ComfyCollectorNodes. Under ComfyCollectorNodes/Loaders, no dependencies beyond the pack (PIL, numpy, torch - all standard ComfyUI).

    The honest take

    If you only ever load images by hand, skip it - the dropdown is fine. The moment you want to sweep, loop, or batch without touching the graph, this is one of the most useful nodes in the pack. Just remember the directory is a raw path string: no ~ expansion, no relative-path guessing, and a wrong path raises a clear "Directory not found" error rather than silently loading nothing.

    CategoryComfyCollectorNodes/Loaders

    Inputs (4)

    NameTypeDefaultDescription
    directorySTRING
    recursiveBOOLEANfalse
    indexINT00–99999
    debugoptBOOLEANfalse

    Outputs (7)

    NameTypeDescription
    imageIMAGE
    maskMASK
    filenameSTRING
    file_pathSTRING
    total_filesINT
    actual_indexINT
    wrappedBOOLEAN