Nodes/ComfyUI_BatchImages/RH Save Image Original Name
ComfyUI Node

RH Save Image Original Name

Save a batch back with its original filenames — folder structure included

By kegeai888·Created 4 months ago·Updated 4 months ago· 0
RH Save Image Original Name
  • images
    manifest[]
    filename_prefixComfyUI

    ComfyUI's stock SaveImage names everything ComfyUI_00001_.png, ComfyUI_00002_.png - great when you're generating fresh art, useless when you're processing a batch someone handed you and need the results to line up with the sources. RHSaveImageOriginalName is the closing half of the round trip: upload a zip of setA/cat.png, setA/dog.jpg, do whatever you do to them in the middle, and this node writes the results back to output/ as setA/cat.png, setA/dog.jpg - same names, same relative folders. If your output has to match your input, this is the node you want at the end of the graph.

    How it works

    It's an output node, so it always runs and the execution cache stops here. It takes three inputs:

    • images - the (processed) IMAGE list.
    • manifest - the JSON string carrying each image's original stem, extension, and relative path inside the zip. This is why the original names survive: nothing in a tensor remembers its filename; the manifest does.
    • filename_prefix - a string, default ComfyUI. Think of it as the top-level folder for this run, not a per-file name. Set it to something like batch_run_01 and everything lands under output/batch_run_01/.

    The save logic is defensive in exactly the ways you'd hope. Every path segment gets sanitized - unsafe characters become underscores, hidden segments and .. are rejected outright - and a commonpath check guarantees nothing can be written outside output/. Filename collisions don't overwrite: the node reserves each target with an exclusive-create flag and bumps to cat_1.png, cat_2.png until it finds a free name. You can run the same batch twice and get a second, non-destructive copy instead of a silently clobbered first run.

    One metadata detail worth knowing: PNG outputs get the prompt and extra_pnginfo embedded, same as core SaveImage, so a PNG result still round-trips as a workflow. JPEG and WebP saves skip it entirely - only PNG has the text chunks that carry a ComfyUI graph, so if you need the workflow to survive, save as PNG. And if your ComfyUI runs with --disable-metadata, nothing gets embedded at all.

    The traps

    The one that bites: images and manifest must match in length, or it errors out. If your middle processing dropped images - say a node filtered some out or an image failed to load upstream - the manifest won't line up and the save refuses to run. That's deliberate, and the fix is to keep counts in sync using RHBatchImages: to select, rather than silently letting the lengths drift. The node even logs and skips individual files that fail to save, but it hard-errors if everything fails.

    Also remember what it's saving: a processed copy under the original name. If you point it at a directory that holds your originals, the collision suffix means you won't overwrite them - which is a kindness, but it means your "original" files now sit next to _1 copies. For a clean dataset you probably want a fresh filename_prefix per run.

    Install

    Same as the rest of the pack, which means almost nothing to install:

    cd ComfyUI/custom_nodes
    git clone https://github.com/kegeai888/ComfyUI_BatchImages
    

    Restart ComfyUI and it shows up under BatchImages. No requirements.txt, no models, no extra pip packages - it uses the torch/PIL/numpy ComfyUI already ships. The full pipeline it belongs to is RHUploadZip_V2 → RHBatchImages: → your processing → this node, and the manifest is the string that ties it together from first to last. For anyone whose job is "take these photos, fix them, give them back the same way," that's the whole workflow in one pack.

    CategoryBatchImages

    Inputs (3)

    NameTypeDefaultDescription
    imagesIMAGEThe images to save.
    manifestSTRING[]
    filename_prefixSTRINGComfyUI

    Outputs (0)

    No outputs