Load Images For Loop
Process a whole folder of images, one at a time
- initial_value1
- initial_value2
- flow
- index
- image
- mask
- name
- value1
- value2
You've got a folder of 200 images and one workflow you want to run over every single one of them. The naive approach - load them as a batch - falls over fast: a 200-image batch of anything heavy will eat your VRAM alive. easy loadImagesForLoop does it the sane way. It's a loop that reads a directory and yields one image per iteration, so your workflow processes image 1, finishes, frees the memory, then processes image 2, and so on. It's the loop-start half of a for-loop that happens to know how to walk a folder.
Why you'd reach for it
Any time you have a batch job where the per-image work is non-trivial: upscale a folder, face-detail a folder, caption a folder, run img2img over a directory of frames. Because each pass handles a single image, memory stays flat no matter how many files are in the folder - the thing a real batch can't promise.
It pairs with easy forLoopEnd, which closes the loop. You wire this node's flow output down through your per-image processing and into the loop-end node; the end node loops back until the folder's exhausted. Values you want to accumulate across iterations (a running list, a counter) ride the initial_value / value sockets around the loop.
The inputs and outputs
directory(STRING) - the folder path to read images from. This is the one required setting.start_index(default 0) - skip the first N files, handy for resuming a partial run.limit(default -1) - cap how many images to process; -1 means all of them.initial_value1/initial_value2(any) - seed values carried into the loop, for accumulating state across iterations.
Per-iteration outputs:
flow(FLOW_CONTROL) - the loop control signal. Wire this toeasy forLoopEnd. This is what makes it a loop, not a one-shot loader.index(INT) - which iteration you're on. Useful for naming outputs or driving an index switch.imageandmask- the current file's image and (if present) alpha mask.name(STRING) - the current file's name, so you can save results under matching filenames.value1/value2- the carried-through loop values.
Installing it
ComfyUI Manager: search ComfyUI Easy Use, install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/yolain/ComfyUI-Easy-Use
then install the requirements (install.bat on Windows, else pip install -r ComfyUI-Easy-Use/requirements.txt) and restart.
Common issues
- You must close the loop. This node needs
easy forLoopEndconnected viaflow, or the loop has no end and won't iterate correctly. A "loadImagesForLoop that only ran once" is almost always a missing or mis-wired loop-end. - The directory path. It reads from a server-side path - the folder as ComfyUI's process sees it, not your desktop. On a cloud or remote instance that's a path on the remote machine. Get the path right and confirm it actually contains readable images.
- Save outputs inside the loop. Since each iteration overwrites the previous image, wire your Save node into the loop body (use the
nameoutput to keep filenames unique) rather than expecting a batch to fall out the end. - Mixed image sizes are fine here - because you're handling one at a time, the images don't need to share dimensions the way a real batch would.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| directory | STRING | — | |
| start_indexopt | INT | 0 | — |
| limitopt | INT | -1-1–10000 | — |
| initial_value1opt | * | — | |
| initial_value2opt | * | — |
Outputs (7)
| Name | Type | Description |
|---|---|---|
| flow | FLOW_CONTROL | — |
| index | INT | — |
| image | IMAGE | — |
| mask | MASK | — |
| name | STRING | — |
| value1 | * | — |
| value2 | * | — |