ComfyUI Node

Folder Image Loader

Folder Image Loader — point it at a directory and get images, masks, and filenames back

By marcoc2·Created 2 years ago·Updated 5 months ago· 1
Folder Image Loader
    • images
    • masks
    • filenames
    directory
    target_width512
    target_height512
    image_load_cap0
    start_index0

    The built-in LoadImage only loads one file at a time, and you pick it from a dropdown. If your job is "process these 400 images that are sitting in a folder," you do not want to be building a graph that reads them one by one. FolderImageLoader is the node that reads an entire directory and hands you the images, their alpha-derived masks, and the filenames - all as lists, ready to feed a batch loop.

    This is the node you reach for when you're doing dataset prep, img2img sweeps over a folder of source images, upscaling an archive, or feeding frames into a processing chain. It also quietly does the "canvas center" thing for you: every image gets pasted centered onto a white canvas of a fixed target size, so you end up with uniform dimensions instead of a chaotic mix of aspect ratios that ComfyUI then has to reconcile.

    How it works

    It scans the directory, sorts the files alphabetically, and loads everything with a valid image extension (png, jpg, jpeg, bmp, gif, webp). For each image it builds a canvas of your target_width × target_height, centers the image on it with a white background, and - this is the nice part - extracts the alpha channel into a companion mask. If your source images are RGBA PNGs with transparency, you get the RGB content and a proper mask in lockstep, which is exactly what you want when you're building a dataset or compositing later.

    The image is pasted centered without rescaling, so images smaller than the canvas get padding and images larger get clipped at the edges. Set target_width/target_height to 0 to just inherit the size of the first image in the folder.

    The inputs and outputs

    Four inputs, and only two really matter most of the time:

    • directory - path to the folder. This one is a plain string, so no file browser dropdown - paste or type the absolute path.
    • target_width / target_height - canvas size, default 512. 0 means "use the first image's size."
    • image_load_cap - 0 loads everything; otherwise it loads only the first N. Handy for testing a workflow on 10 images before committing to the whole folder.
    • start_index - skips the first N files, for resuming a job that already processed part of the set.

    Outputs are three lists: images, masks, and filenames. The filenames output is the quiet hero - when you're saving processed results back and want the original name preserved, that list is how you map output to input.

    Installing it

    Part of the AnotherUtils pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/marcoc2/ComfyUI-AnotherUtils.git
    

    Restart ComfyUI. Or use ComfyUI Manager and search "AnotherUtils". No extra dependencies to install.

    Common issues

    The two things that trip people up: first, the directory input is a raw string, and a typo means a FileNotFoundError on the node - there's no picker to save you. Double-check the path. Second, the white canvas means images with very different aspect ratios get padded, and that white border travels with them downstream. If you're about to train on this or want clean edges, either pre-crop your folder or set target_width/target_height to 0 so the canvas matches your first image.

    Also note this centers and pads rather than stretching. That's usually what you want for datasets - squashing everything to one size ruins proportions - but it means you're not getting letterbox-free uniform images unless you prepare them first.

    CategoryAnotherUtils

    Inputs (5)

    NameTypeDefaultDescription
    directorySTRING
    target_widthINT5120–81920 = use first image width
    target_heightINT5120–81920 = use first image height
    image_load_capINT00–99990 = unlimited
    start_indexINT00–9999Skip first N images

    Outputs (3)

    NameTypeDescription
    imagesIMAGE
    masksMASK
    filenamesSTRING