Random Image Loader Tlant
Load a Random Image From a Folder, or Lock One In
- image
- file_path
The image-flavored cousin of the pack's random text loaders: point it at a folder of images and it grabs one at random and hands it to your graph as a proper IMAGE tensor. Think style-reference roulette for img2img, IP-Adapter, or ControlNet - feed it a folder of reference shots and every run gets a different one. What makes it better than just stubbing random.choice into a custom loader is the is_fixed toggle, which lets you freeze a pick so a good reference doesn't vanish on the next execution.
How it works
It scans path for images (.jpg, .jpeg, .png, .bmp, .tiff, .tif, .webp, .gif), recursively by default, then random.choices one. The chosen file is loaded with PIL, EXIF-transposed, converted to RGB, normalized, and returned as a float tensor in ComfyUI's [batch, height, width, channels] layout.
The is_fixed toggle is the interesting part. It works through IS_CHANGED: with is_fixed off, the node returns a random value from IS_CHANGED so ComfyUI re-executes and re-rolls every run. With it on, IS_CHANGED returns a stable value, so the node's output is cached and the current selection sticks - you keep the image you picked until you flip the toggle off again. That's a clean way to "hold" a reference mid-workflow.
Inputs and outputs
path- the folder to scan (absolute path).recursive- a real boolean checkbox here (not a string enum, unlike the txt loaders). Default on.is_fixed- boolean, default off. On = keep the current image.
Outputs: image (IMAGE) and file_path (STRING, the absolute path of the selected file). When things go wrong it doesn't raise - it returns a black 512×512 placeholder image and puts the error text in file_path, which is a nice way to keep the graph alive but a confusing one if you don't notice the black frame.
Install
One pack, one install:
cd ComfyUI/custom_nodes
git clone https://github.com/Tlant/ComfyUI-OllamaPromptsGeneratorTlant
restart ComfyUI, or use Manager ("Random Image Loader Tlant"). No models, no heavy deps.
Where people get tripped up
- The black-frame error mode. A missing path or an empty folder yields a black 512×512 tensor and the error text in
file_path. The workflow keeps running - which is kind of the point - but if you ever see a sudden black image, checkfile_path. is_fixedis a workflow run, not a global lock. It prevents re-rolls via caching, but if you change any upstream input the cached output can invalidate. For a truly permanent reference, hardcode the path or use a static loader.- Recursion default is on. Point it at a folder with unexpected subfolders and you'll draw from a bigger pool than you intended.
For random reference selection with a freeze option, it's a tidy little node. Pair it with a fixed seed elsewhere in the workflow if you want re-rolls to be reproducible too.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| path | STRING | — | |
| recursive | BOOLEAN | true | — |
| is_fixed | BOOLEAN | false | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| file_path | STRING | — |