Nodes/KJNodes for ComfyUI/Load Images From Folder (KJ)
ComfyUI Node Runs on cloud

Load Images From Folder (KJ)

Batch a whole directory into one workflow

By kijai·Created 3 years ago·Updated about 11 hours ago· 2,930
Load Images From Folder (KJ)
    • image
    • mask
    • count
    • image_path
    folder
    width1024
    height1024
    keep_aspect_ratio
    image_load_cap0
    start_index0
    include_subfoldersfalse

    When you need to run a workflow over a pile of images - a whole folder of them - you don't want to load them one at a time. Load Images From Folder (KJ) points at a directory and pulls every image in it into a single batch, resized to a common size so they stack cleanly. Its description is exactly this: "Loads images from a folder into a batch, images are resized and loaded into a batch." It's the front door for bulk processing: batch upscaling, batch img2img, feeding a folder of frames into a video workflow, dataset prep.

    How it works

    You give it a folder path and target dimensions. It reads the images, resizes each to those dimensions, and returns them as one batched IMAGE tensor plus some metadata. Because everything in a ComfyUI batch has to share a size, the resize isn't optional - and the node gives you control over how it makes them match, which is the part that actually matters.

    The inputs that matter

    • folder - the directory path to load from. This is the whole point; get the path right and most of your problems disappear.
    • width / height (default 1024) - the size every image gets resized to. There's a -1 sentinel available if you want to leave a dimension unconstrained.
    • keep_aspect_ratio (crop, pad, or stretch) - how to reconcile mismatched source shapes with your target size. crop fills the frame and trims overflow, pad letterboxes with borders, stretch distorts to fit. crop is usually what you want for generation; stretch is what you want almost never.

    Three optional dials handle big folders: image_load_cap (stop after N images - 0 means all), start_index (skip the first N, for resuming or paging through a huge set), and include_subfolders (recurse, off by default).

    Four outputs: image (the batch), mask (any alpha channels, as masks), count (how many loaded, an INT), and image_path (the paths, as a string). The count output is handy for driving downstream loops or sanity-checking you got what you expected.

    Where it wires in

    At the very start of a batch pipeline. The image output feeds whatever you're running over the set - an upscaler, a sampler in img2img mode, a color-match pass. image_load_cap and start_index together let you process a giant folder in chunks so you don't try to hold ten thousand images in VRAM at once.

    Installing it

    Part of kijai's KJNodes pack.

    • ComfyUI Manager - search KJNodes for ComfyUI, install, restart.
    • Manual - cd ComfyUI/custom_nodes && git clone https://github.com/kijai/ComfyUI-KJNodes, then pip install -r requirements.txt, and restart.

    No dependencies of note.

    Common issues

    Path problems are 90% of the support questions on nodes like this. The folder path has to be one ComfyUI can actually see from where it's running - an absolute path is safest, and on a remote or containerized ComfyUI (like a cloud instance) "my desktop folder" isn't reachable at all. If the node loads nothing, check the path before anything else.

    The other big one is memory. A folder-load builds one batch, and a batch of hundreds of 1024px images is a lot of tensor to hold at once - that's how you OOM before the sampler even starts. Use image_load_cap to process in manageable chunks, and start_index to walk through the rest across runs. Finally, mind keep_aspect_ratio: if your outputs come back squished, you're on stretch when you wanted crop or pad.

    CategoryKJNodes/image

    Inputs (7)

    NameTypeDefaultDescription
    folderSTRING
    widthINT1024
    heightINT1024
    keep_aspect_ratioCOMBO3 options: crop, pad, stretch
    image_load_capoptINT0
    start_indexoptINT0
    include_subfoldersoptBOOLEANfalse

    Outputs (4)

    NameTypeDescription
    imageIMAGE
    maskMASK
    countINT
    image_pathSTRING