Nodes/😸 YFG Comical Nodes/🐯 YFG Random Image From Directory
ComfyUI Node

🐯 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

By gonzaluΒ·Created 2 years agoΒ·Updated 10 days agoΒ· 29
🐯 YFG Random Image From Directory
    • image
    • path_current
    • index_current
    • filename_current
    • width
    • height
    • sha256
    • total_count
    • path_previous
    • index_previous
    β—„image_directoryβ€”β–Ί
    β—„include_subdirstrueβ–Ί
    β—„selection_moderandomβ–Ί
    β—„show_previewfalseβ–Ί
    β—„index0β–Ί
    β—„filename_queryβ€”β–Ί
    β—„random_sourceautoβ–Ί
    β—„ensure_uniquefalseβ–Ί
    β—„unique_scopeβ–Ύβ–Ί
    β—„history_size512β–Ί
    β—„time_window_sec0β–Ί
    β—„retry_limit16β–Ί
    Category🐯 YFG/πŸ–ΌοΈ Loaders

    Inputs (12)

    NameTypeDefaultDescription
    image_directorySTRINGDirectory containing image files to pick from.
    include_subdirsBOOLEANtrueIf true, search subfolders recursively.
    selection_modeCOMBOrandomHow to pick the image: random, by_index, by_filename, or by_query (wildcard).
    show_previewBOOLEANfalseIf enabled, show a preview thumbnail (and publish UI preview metadata for downstream nodes).
    indexINT00–18446744073709550000Used only for by_index. Out-of-bounds is clamped: <0β†’0, >=countβ†’last.
    filename_querySTRINGUsed by by_filename/by_query. by_query supports * and ? wildcards.
    random_sourceCOMBOautoauto uses random.org if API key exists; otherwise uses local random.
    ensure_uniqueBOOLEANfalseIf true, avoid recently-used images (based on history_size/time_window_sec).
    unique_scopeCOMBOdirectory: uniqueness tracked per-directory. global: shared across all directories.
    history_sizeINT5121–100000How many recent selections to remember for uniqueness checks.
    time_window_secINT00–604800If >0, forget uniqueness history entries older than this many seconds.
    retry_limitINT161–999Maximum attempts to find a unique candidate before falling back.

    Outputs (10)

    NameTypeDescription
    imageIMAGEThe selected image as an IMAGE tensor.
    path_currentSTRINGFull path to the currently selected image file.
    index_currentINT0-based index of the selected image within the (sorted) file list.
    filename_currentSTRINGFilename of the selected image (basename only).
    widthINTImage width (pixels).
    heightINTImage height (pixels).
    sha256STRINGSHA-256 hash of the file contents (useful for de-duping / auditing).
    total_countINTTotal number of images discovered in the directory (and subdirs if enabled).
    path_previousSTRINGFull path to the previously selected image in this ComfyUI session.
    index_previousINT0-based index of the previously selected image in this ComfyUI session.