Load Images For Loop with Background
Loop over a folder of images without fighting ComfyUI's batch system
- initial_value1
- initial_value2
- flow
- index
- image
- mask
- name
- value1
- value2
ComfyUI doesn't do real loops. You get batch sizes, which are fine when every image goes through the exact same chain, and miserable when each one needs different handling. This node is the escape hatch: it iterates over every image in a directory one at a time, handing you a FLOW_CONTROL token plus the current image, mask, index, and filename so you can actually branch per iteration.
It's a port of ComfyUI-Easy-Use's "Load Images For Loop" node, with the pack's signature addition: a background_color option that composites transparent PNGs over a solid color as it loads them.
How it works
You give it a directory; it filters for image files (jpg, jpeg, png, webp, bmp, tiff), sorts them by name, slices by start_index/limit, and then uses ComfyUI's internal GraphBuilder to expand into a loop. Each pass pulls the next file, decodes it, and returns one image plus its mask and stem name.
Here's the dependency you need to know before you build anything on this: the expanded loop instantiates Easy-Use's easy whileLoopStart node. In plain terms, you need ComfyUI-Easy-Use installed for the loop to actually loop. Without it, the node falls back to a stub that just hands you the first image. Install Easy-Use alongside this pack or you'll be chasing a confusing "node not found" in the executed graph.
Inputs and outputs
- directory - absolute path to the folder. An empty or bad path raises a
FileNotFoundErrorimmediately, which is honest behavior. - background_color -
defaultleaves transparent pixels alone; otherwise white/black/gray/red/green/blue/yellow get composited behind the image. - start_index / limit - where to start and how many to take (
limitof-1= everything). - initial_value1 / initial_value2 - any-typed values that ride along through the loop, so you can carry state (a running sum, a seed list, a counter) between iterations.
Outputs: flow (the loop-control signal that drives the iteration), index, image, mask, name (the file's stem, so you know which iteration you're on), and value1 / value2 for the carried values.
Install
Standard pack install - Manager (search "ComfyUI-AutoFlow") or:
cd ComfyUI/custom_nodes
git clone https://github.com/ZXL-Xinram/ComfyUI-AutoFlow
Restart after cloning. Then separately make sure ComfyUI-Easy-Use is installed, because this node leans on it. No models to download.
Where people get burned
- No Easy-Use → no loop. The most common failure, and it fails silently-ish: the graph just doesn't expand. Install ComfyUI-Easy-Use (
yolain/ComfyUI-Easy-Use) via Manager and restart. start_indexpast the end of the list raises a ValueError. Sorted order matters - it's filename-sorted, soimg10.pngsorts beforeimg2.png. Zero-pad your filenames.- The background color only kicks in for files that actually carry an alpha channel (or a palette with transparency). An ordinary opaque JPG is passed through untouched.
It's a young node with a small community footprint, so expect rough edges, but for per-frame work that needs branching it beats the batch system. Pair it with the pack's own Condition Checker + Condition Assignment to make each iteration decide its own path.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| directory | STRING | — | |
| background_color | COMBO | default | 8 options: default, white, black, gray, red, green, +2 |
| 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 | * | — |