ComfyUI Node

Image Loader

Load an Image by Folder Path Instead of Hunting the Dropdown

By 5agado·Created 12 months ago·Updated 17 days ago· 1
Image Loader
    • image
    • mask
    • image_path
    folder_path
    image_idx0
    random_idxfalse
    sort_bydate
    reversefalse
    seed42

    ComfyUI's built-in Load Image picks from the input folder via a dropdown, which is great until you have 900 images or you're feeding a pipeline that processes a whole folder one image at a time. The Image Loader from the Sagado pack works differently: you give it a folder path and an index, and it hands you that image - plus its alpha mask and the path it loaded. It's the "I want to process my own directory, in order, without renaming files into the input folder" node.

    How it works

    Behind the scenes it scans the folder for png, jpg, jpeg, and webp files, sorts them by name or creation date (or shuffles), optionally reverses the order, and picks one by index - or at random if you flip that flag. Then it loads it with EXIF orientation respected (so phone photos aren't sideways), converts to RGB, and builds a mask from the alpha channel. The mask is worth knowing about: it's 1 - alpha, so an opaque image gives you a zeroed mask and transparent regions show up as mask values. It comes out of the box wired for "alpha means the thing I want to cut out."

    Inputs and outputs

    • folder_path (STRING) - absolute path to your image directory.
    • Optional: image_idx (INT, default 0), random_idx (BOOLEAN), sort_by (STRING: name / date / shuffle), reverse (BOOLEAN), seed (INT, default 42 - used when randomizing).
    • Outputs: image (IMAGE), mask (MASK), image_path (STRING).

    The image_path output is the sleeper useful one - pass it to nodes that want a filename, or use it for bookkeeping about which image you just processed.

    Install

    Same as the whole pack: ComfyUI Manager → "Sagado Nodes for ComfyUI", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/5agado/ComfyUI-Sagado-Nodes
    pip install -r ComfyUI-Sagado-Nodes/requirements.txt
    

    Restart. It needs pillow, which ships in the pack's requirements.

    Where it bites

    Two failure modes, both worth knowing before you build a workflow on it. First, if the folder path is invalid or the folder has no supported images, it doesn't throw a hard error - it prints a message and returns None outputs, which then poisons everything downstream with a confusing "NoneType" error. Second, an out-of-range image_idx does the same quiet-None thing. You'll want something downstream that can tolerate a missing image, or you'll be hunting a log line.

    The random path uses numpy's RNG with your seed, so it's reproducible if you keep the seed fixed and non-reproducible if you set random_idx and let the seed spin. It's a solid, simple loader - just don't expect it to yell at you when you point it at a typo'd path.

    CategorySagado-Nodes

    Inputs (6)

    NameTypeDefaultDescription
    folder_pathSTRING
    image_idxoptINT0
    random_idxoptBOOLEANfalse
    sort_byoptSTRINGdate
    reverseoptBOOLEANfalse
    seedoptINT42

    Outputs (3)

    NameTypeDescription
    imageIMAGE
    maskMASK
    image_pathSTRING