Nodes/ComfyBreakAnim/RandomImageFromDir
ComfyUI Node

RandomImageFromDir

A random image from a folder — that's the whole node

By LonicaMewinsky·Created 3 years ago·Updated 2 years ago· 30
RandomImageFromDir
    • Random Image
    dirC:/Poses

    This is the node the author forgot he shipped. RandomImageFromDir is categorized as _for_testing, it's the only one of the five in this pack that doesn't appear in the README at all, and its entire job is to pick a random .png, .jpg, or .jpeg out of a folder and hand it to you as an IMAGE. That's it. No controls, no seeding, no filtering. One input (dir, a path string defaulting to C:/Poses), one output (Random Image).

    So why does it exist, and why should you care? The default path is the tell: C:/Poses. The author was building animation workflows where you img2img across a set of pose references, and instead of hand-picking a pose image every run, he wanted the node to roll the dice for him. Drop a folder of reference images in, wire Random Image into an IPAdapter or a control net, and every queue gives you a different pose to work from. It's a crude A/B sampling tool - useful for hammering through style tests without touching the mouse.

    The one bit of real mechanism here is IS_CHANGED, which returns random.random(). In ComfyUI, that's the standard trick to force a node to re-execute on every queue instead of caching its output - without it, ComfyUI would compute the "random" pick once and then treat it as done, which would make the node useless. So yes, it genuinely re-rolls each run. It also loads through PIL, which means it doesn't need the OpenCV dependency the rest of the pack drags in - though you'll get that dependency anyway since they all ship together.

    Honest limitations, all from the source: the extension filter is lowercase and hardcoded, so .PNG or .webp files are invisible to it. An empty folder, or one with no matching files, makes random.choice throw an IndexError - no graceful message. And since nothing here sorts or dedupes, you can get the same image twice in a row. That's fine for a test node; it would be annoying for real work.

    Reach for this only for the quick-and-dirty case it was built for: grab a random reference from a folder on each run. For anything more deliberate, a normal LoadImage and your own hand is the better tool. But it installs in the same command as the rest of the pack, costs nothing, and when you need a random pose on demand, it delivers.

    Category_for_testing

    Inputs (1)

    NameTypeDefaultDescription
    dirSTRINGC:/Poses

    Outputs (1)

    NameTypeDescription
    Random ImageIMAGE