π― YFG Random Image From Directory
YFG Random Image From Directory (v1.3.6) Loads an image from a directory (optionally including subfolders). Modes: β’ random: chooses a random image. β’ by_index: chooses a specific image index (clamped to [0..last]). β’ by_filename: chooses the first match for an exact/substring filename. β’ by_query: wildcard/glob-like match (e.g. *.png), then random among matches. Uniqueness: β’ If ensure_unique=true, recently-used images are avoided within the configured history/time window. Random source: β’ auto uses random.org if API key is present, otherwise local random. Changelog: 1.3.6 Fixed directory browser: corrected JS import path and added missing Python API routes (/yfg/dir_browse, /yfg/dir_history). Auto-saves used directories to history on each run. 1.3.5 Added built-in preview output for UI-driven nodes (Resolution Master compatible) Strict by_index behavior, shuffle-bag uniqueness, full tooltip support
- image
- path_current
- index_current
- filename_current
- width
- height
- sha256
- total_count
- path_previous
- index_previous
Inputs (12)
| Name | Type | Default | Description |
|---|---|---|---|
| image_directory | STRING | Directory containing image files to pick from. | |
| include_subdirs | BOOLEAN | true | If true, search subfolders recursively. |
| selection_mode | COMBO | random | How to pick the image: random, by_index, by_filename, or by_query (wildcard). |
| show_preview | BOOLEAN | false | If enabled, show a preview thumbnail (and publish UI preview metadata for downstream nodes). |
| index | INT | 00β18446744073709550000 | Used only for by_index. Out-of-bounds is clamped: <0β0, >=countβlast. |
| filename_query | STRING | Used by by_filename/by_query. by_query supports * and ? wildcards. | |
| random_source | COMBO | auto | auto uses random.org if API key exists; otherwise uses local random. |
| ensure_unique | BOOLEAN | false | If true, avoid recently-used images (based on history_size/time_window_sec). |
| unique_scope | COMBO | directory: uniqueness tracked per-directory. global: shared across all directories. | |
| history_size | INT | 5121β100000 | How many recent selections to remember for uniqueness checks. |
| time_window_sec | INT | 00β604800 | If >0, forget uniqueness history entries older than this many seconds. |
| retry_limit | INT | 161β999 | Maximum attempts to find a unique candidate before falling back. |
Outputs (10)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | The selected image as an IMAGE tensor. |
| path_current | STRING | Full path to the currently selected image file. |
| index_current | INT | 0-based index of the selected image within the (sorted) file list. |
| filename_current | STRING | Filename of the selected image (basename only). |
| width | INT | Image width (pixels). |
| height | INT | Image height (pixels). |
| sha256 | STRING | SHA-256 hash of the file contents (useful for de-duping / auditing). |
| total_count | INT | Total number of images discovered in the directory (and subdirs if enabled). |
| path_previous | STRING | Full path to the previously selected image in this ComfyUI session. |
| index_previous | INT | 0-based index of the previously selected image in this ComfyUI session. |