Nodes/Comfyui_TextBatch_aidec/Load Image By Index (延遲載入)
ComfyUI Node

Load Image By Index (延遲載入)

Grab one image from a folder, low memory

By aidec·Created 2 years ago·Updated 9 months ago· 19
Load Image By Index (延遲載入)
    • image
    • mask
    • filename
    • full_path
    • total_files
    • status
    directory
    index0
    load_alwaysfalse

    Load Image By Index does the obvious thing its name promises: point it at a folder, give it a number, and it loads that one image - the 5th file, the 42nd file, whatever index says. No batch, no loading the whole directory into memory, just the single image you asked for.

    That "single, on demand" behavior is the useful part. In aidec's batch pack the whole design philosophy is serial processing - walk a folder one image at a time instead of stacking it all in VRAM - and this node is the low-level building block for exactly that. Drive index from a queue counter and you've got a lazy folder loader that stays cheap no matter how many thousands of files are sitting in the directory. It's the "延遲載入" (lazy-load) sibling to the batch loaders.

    How it works

    It scans the directory to figure out the file list and its length, then reads only the file at your index off disk. Because it never holds more than one image at a time, memory stays flat whether the folder has 20 images or 20,000 - the same reason Image Queue Processor Pro (which bundles this same lazy approach with a queue) is the recommended batch-img2img node. Load Image By Index is that behavior exposed as a plain, wire-it-yourself picker.

    The inputs that matter

    • directory - the folder to read from.
    • index - which file to load (0-based). This is the knob you'd normally drive from a queue node's current_index so it advances through the folder as the batch runs.
    • load_always (optional) - force a re-read instead of serving ComfyUI's cached result. Turn it on when the folder's contents change between runs and you need the loader to actually look again.

    Outputs: image and mask for your pipeline, plus filename and full_path for the file it just loaded, total_files (the folder's length - handy as a loop bound), and status. The filename outputs mean you can keep output names matched to inputs without a separate lookup node.

    Installing it

    cd ComfyUI/custom_nodes && git clone https://github.com/aidec/Comfyui_TextBatch_aidec, then restart ComfyUI (or ComfyUI Manager → Install via Git URL). No models or extra dependencies. It's under the image category, not TextBatch.

    Where people get burned

    • Index out of range. Ask for image 500 in a 200-file folder and there's nothing there. Use the total_files output as your upper bound (or feed the index from a queue that knows the count) so you don't run off the end.
    • File ordering. "Index 7" means the 7th file in whatever order the directory scan returns, which is typically sorted by name - so img10.png may land before img2.png unless your names are zero-padded. If the order matters, pad your filenames (img002, img010).
    • Server-side paths. On a hosted/serverless ComfyUI the folder must exist on the server's filesystem, not your local machine.
    • Stale cache. Swapped the files but getting the old image back? That's caching - flip load_always on.

    If you want a queue-and-loader in one, reach for Image Queue Processor Pro. If you want the raw lazy picker to wire up yourself, this is it.

    Categoryimage

    Inputs (3)

    NameTypeDefaultDescription
    directorySTRING
    indexINT0
    load_alwaysoptBOOLEANfalse

    Outputs (6)

    NameTypeDescription
    imageIMAGE
    maskMASK
    filenameSTRING
    full_pathSTRING
    total_filesINT
    statusSTRING