Nodes/Lostless Nodes/Lostless Random Image
ComfyUI Node

Lostless Random Image

Folder of images in, random pick out — with a preview that survives restart

By lostlessvisuals·Created 7 months ago·Updated 10 days ago· 0
Lostless Random Image
    • image
    • selected_filename
    folder_path
    recursivetrue
    allowed_extensions.png,.jpg,.jpeg,.webp,.bmp,.gif,.tif,.tiff
    selected_filename
    lock_randomizefalse
    trigger0
    selected_path

    The job is simple and everywhere: you've got a folder of images - style references, face-swap candidates, input frames for a batch - and you want to cycle through them by clicking a button instead of typing a path into a Load Image node by hand. The stock ComfyUI way is painful precisely because you're editing a string field each iteration and hoping you typed it right. Lostless Random Image picks a file from a folder for you, shows you the chosen image on the node, and remembers it across restarts so the preview you're looking at is the image the graph will actually run.

    The name is a bit of a lie in the reassuring direction: it doesn't call any API and needs no key. Everything is local. The node ships frontend code that adds two buttons - Randomize Image and Load Image - and they talk to small endpoints the pack registers on your own ComfyUI server (/lostless/random-image, /lostless/image-preview, /lostless/select-image). Click Randomize and the server picks a random file from your folder, writes it into the node's saved selection, and fetches a preview thumbnail. Click Load Image and it opens a native file dialog on the machine running ComfyUI. On workflow load, the node re-resolves the saved selection and restores the preview - which is the feature you didn't know you needed until you've reopened a workflow and had no idea which image a random node was about to feed in.

    The inputs that matter

    Seven required inputs, but you'll genuinely set maybe three:

    • folder_path - absolute path on the ComfyUI machine. The randomize happens server-side, so a relative path that resolves in your browser won't help.
    • recursive - "Subfolders" toggle. Default ON; turn it off if you want a flat folder only.
    • allowed_extensions - the comma list of image types, default .png,.jpg,.jpeg,.webp,.bmp,.gif,.tif,.tiff. Trim it if you only want PNGs.
    • lock_randomize - the Broadcast Lock. When ON, the pack's Randomize Button will skip this node. More on that in the button's own writeup.
    • selected_filename - read-only; set by the buttons. It's the record of your last pick.
    • trigger - an INT that's there to poke the node into re-running. Wire the Randomize Button's output here.
    • selected_path - hidden in the UI; it's the full path behind the selection.

    The outputs

    • image - an IMAGE tensor of the picked file, ready to feed a sampler, VAE encode, img2img, whatever.
    • selected_filename - a STRING with the file's basename. Handy if you want the filename in a prompt, a filename-saver, or a text node.

    How the loop actually runs

    Clicking Randomize updates the node's widgets - it does not queue a run by itself. The new image reaches the image output on the next graph execution. So the rhythm is: click Randomize → see the preview → queue the prompt. If you have auto-queue on and wire a Randomize Button's trigger into this node, one click does the picking and re-runs the graph, which is the intended multi-node flow.

    Install & troubleshooting

    From ComfyUI Manager, search for Lostless Nodes. Or clone it manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/lostlessvisuals/comfyui-lostless-nodes
    python -m pip install -r ComfyUI/custom_nodes/comfyui-lostless-nodes/requirements.txt
    

    Restart after installing. No models to download.

    Where people get burned: a folder path the ComfyUI process can't read - you'll get a No images found error with the resolved path right in it, so check that it's absolute and that the extensions match what's actually in the folder. And remember the preview is just a preview: until you queue, nothing downstream has seen the new image.

    Categorylostless/nodes

    Inputs (7)

    NameTypeDefaultDescription
    folder_pathSTRING
    recursiveBOOLEANtrue
    allowed_extensionsSTRING.png,.jpg,.jpeg,.webp,.bmp,.gif,.tif,.tiff
    selected_filenameSTRING
    lock_randomizeBOOLEANfalse
    triggerINT0
    selected_pathSTRING

    Outputs (2)

    NameTypeDescription
    imageIMAGE
    selected_filenameSTRING