ComfyUI Node

Load Image Newest

Point it at a folder and it always grabs your latest render

By nova452·Created 3 months ago·Updated a day ago· 524
Load Image Newest
    • image
    • mask
    • filename
    • caption
    • metadata
    ◄directory_path►
    ◄cap1►

    Here's the loop this node kills. You render something elsewhere - Krita, Photoshop, an A1111 instance, another ComfyUI tab, a phone upload landing in a sync folder - and now you want it back in the graph as an img2img input. The normal answer is to upload it by hand, every time. LoadImageNewest skips that: give it a directory and a count, and it loads the most recently modified images in there. Hit queue again and it picks up whatever you dropped in since.

    What it returns

    Five outputs, all of them lists - that matters, and it's the first thing that trips people up:

    • image - the loaded image batch, newest first
    • mask - the inverted alpha channel, exactly like core LoadImage: transparent areas come out as 1.0. A JPEG with no alpha gives you an all-zero mask, not an error.
    • filename - the basename, so you can build output names from the input name
    • caption - contents of a sibling .txt with the same basename, or an empty string if there isn't one
    • metadata - the file's embedded PNG text chunks, newline-joined

    That caption output is doing something specific: it's the dataset sidecar convention, 0001.png next to 0001.txt, the same pairing kohya and ai-toolkit read. So this node doubles as a training-set inspector - point it at a dataset folder and you get image plus caption per item, without a captioner in the loop.

    And metadata is quietly the most interesting output, because a PNG that came out of ComfyUI carries its entire embedded workflow and prompt graph in those text chunks. Point this node at your own output folder and that output hands you the whole previous graph as one very long string. Useful when you want to know what produced a file; mildly dangerous when you wire it into something that wasn't expecting a novel.

    Why it reruns when it should

    The node overrides IS_CHANGED to hash the paths and modification times of the images it selected. When a new file lands in the directory, the hash changes, the cache is invalidated, and the graph re-executes. That's what makes "just queue again" work as an interaction instead of returning the cached result from three runs ago - the same always-rerun trick described in our node-plumbing notes, done with a content hash rather than the NaN sledgehammer.

    The two fields

    directory_path - the folder to scan. Type an absolute path.

    cap - how many of the newest images to load, 1 to 1024. Default is 1, which is the sane choice for an img2img source. Raise it and you get a batch, one item per image, all five outputs in step.

    Recognised extensions: png, jpg, jpeg, webp, bmp, tiff, gif.

    Install

    ComfyUI Manager → Rebalance Pack, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/nova452/Rebalance-Pack.git
    # restart ComfyUI, then hard-refresh the browser
    

    No requirements.txt, no model files. Same pack, same caveat as its siblings: if the old ComfyUI-ConditioningKrea2Rebalance folder is still installed alongside it, remove it.

    Where people get burned

    Relative paths. The node normalises separators (so a pasted Windows path with backslashes is fine) and then resolves anything non-absolute against the process's working directory - not ComfyUI/input, not your workflow file. images/ means "wherever ComfyUI was launched from", which is rarely where you think. Use the full path.

    "Newest" is modification time, not filename. Copying, restoring or syncing a folder can reorder it - some tools preserve mtimes, some rewrite them - so a file can be newest by name and third by mtime. Don't rely on sorted thinking.

    "No images found in directory" or "Invalid directory path". The node errors rather than returning nothing, which is the right call but means an empty folder breaks the queue instead of quietly doing nothing. Watch out for this on a freshly created folder you haven't dropped anything into yet.

    Half-written files. If something else is still writing the newest file when you queue, you're loading a partial image. Save-then-queue, never simultaneously.

    List outputs into nodes that want one item. With cap above 1 you're emitting a batch, and the mask, filename and metadata outputs line up positionally with it. Most nodes will batch them happily; anything that expects a single image will complain or take the first one.

    CategoryRebalance-Pack/foundational

    Inputs (2)

    NameTypeDefaultDescription
    directory_pathSTRINGPath to the directory containing images.
    capINT11–1024Number of newest images to load.

    Outputs (5)

    NameTypeDescription
    imageIMAGE—
    maskMASK—
    filenameSTRING—
    captionSTRING—
    metadataSTRING—