Nodes/Nilor Nodes by Nilor Corp/๐Ÿ‘บ Load Image By Index
ComfyUI Node

๐Ÿ‘บ Load Image By Index

Load images from a folder by a seed-controlled index, not a dropdown

By nilor-corpยทCreated 2 years agoยทUpdated 6 months agoยท 6
๐Ÿ‘บ Load Image By Index
    • image
    • filename
    • filepath
    โ—„image_directoryโ–บ
    โ—„seed0โ–บ
    โ—„sort_modefilenameโ–บ
    โ—„reverse_sortfalseโ–บ

    ComfyUI's built-in Load Image makes you pick a file from a dropdown. That's fine for a few images and maddening for hundreds - you can't drive a batch pipeline from a dropdown. Load Image By Index inverts the model: you point it at a directory, and it picks an image by index, where the index comes from a seed input you can wire to anything. Programmatic image loading, finally.

    How it works

    Inputs:

    • image_directory - the folder to scan.
    • seed - used as the index, not a random seed. This is the key insight.
    • sort_mode - filename (default), creation_time, modification_time, or size, which decides what "index N" means.
    • reverse_sort - flips the order.

    The node lists the directory, filters to common image extensions (png, jpg, jpeg, webp, bmp, gif - case-insensitive, notably more generous than the pack's counter node), sorts per sort_mode, then picks seed % len(files). That modulo is important: out-of-range indexes wrap around rather than erroring, so seed 999 on a 10-image folder loads image 9. Outputs are the image tensor, the filename (basename), and the filepath (full path) - so you get the identity of what you loaded, which is exactly what you want when a workflow is iterating over a folder.

    The tricks worth knowing

    It's an index, not a randomizer. Same seed, same sorted list, same image, every time. To walk through a folder sequentially, feed seeds 0, 1, 2โ€ฆ from a counter or ๐Ÿ‘บ List of Ints. To randomize which image loads, you need a seed source that varies - the pack's ๐Ÿ‘บ User Input (Seed) is built for exactly that.

    Sorting changes what a seed means. If you're loading "image 5" you must know the sort order to predict which file that is. Filename sort is stable and predictable; creation-time sort is OS-dependent and can reorder if files are copied. The IS_CHANGED hook in the source only keys on the seed, so changing just sort_mode or reverse_sort may not trigger a re-execute - if you change the sort and the preview doesn't update, nudge the seed.

    The folder must exist. Missing directory โ†’ hard error. And if the folder is empty or has no supported images, it errors too - there's no graceful "no files" path. Filter first with ๐Ÿ‘บ Count Images In Directory if you want a workflow that survives empty folders.

    Performance. It rescans and re-sorts the directory on every execution. Fine for hundreds of files, wasteful if you're re-loading the same index repeatedly in a loop - nothing is cached. Also, it loads the whole image into memory each call; don't feed it a folder of 4K raws if you only need thumbnails.

    Install

    ComfyUI Manager (search "Nilor Nodes") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/nilor-corp/nilor-nodes
    cd nilor-nodes && pip install -r requirements.txt
    

    Restart ComfyUI; it's under Nilor Nodes ๐Ÿ‘บ โ†’ IO. Needs only PIL/torch.

    Bottom line

    The right answer to "I want a workflow that picks images from a folder by number." Pair the seed input with any index source and you have a loop, a random sampler, or a folder walker in one node. Just keep the modulo-wrap and the re-scan cost in mind, and it'll quietly replace a hundred dropdown clicks.

    CategoryNilor Nodes ๐Ÿ‘บ/IO

    Inputs (4)

    NameTypeDefaultDescription
    image_directorySTRINGโ€”
    seedINT00โ€“18446744073709550000โ€”
    sort_modeCOMBOfilename4 options: filename, creation_time, modification_time, size
    reverse_sortBOOLEANfalseโ€”

    Outputs (3)

    NameTypeDescription
    imageIMAGEโ€”
    filenameSTRINGโ€”
    filepathSTRINGโ€”