Nodes/ComfyUI-HQ-Image-Save/Save Image And Prompt (incremental)
ComfyUI Node

Save Image And Prompt (incremental)

Save image + prompt pairs that never collide

By spacepxl·Created 3 years ago·Updated 6 months ago· 102
Save Image And Prompt (incremental)
  • image
  • alpha
    filepathfolder path
    filename_prefix
    zero_padding5
    image_typepng
    prompt

    Every time you hit Run, this node writes your image to a folder under a new numbered filename and drops a matching .txt next to it holding your prompt. Run it ten times and you get img_00001.png through img_00010.png, each with a sidecar caption. It's the dataset-builder's friend: the natural way to collect image + prompt pairs for LoRA training, or to keep a running log of an img2img experiment where you want to remember what you fed the model.

    Here's the catch that makes this a "hidden gem" rather than a documented one: it's not in the pack's README at all. The README only covers the EXR and latent nodes, so you find these prompt-save nodes by scrolling the node list. They work fine - just under-documented.

    How it works

    The "incremental" part is the whole trick. On each run it scans the target folder for the highest existing number that matches your filename_prefix, then starts from one past that. No overwrite logic, no collisions, nothing to reason about - save again, get the next file. Each image is written with the counter zero-padded to zero_padding digits (5 by default, so you get 00001), and the prompt you feed into the optional prompt input is written to a .txt sidecar with the same base name.

    It's a proper output node: it processes whole batches (each frame gets its own number, and the same prompt is written to every sidecar), and it can take an alpha MASK and append it as a fourth channel if you're saving with transparency.

    The inputs that matter

    • filepath - the folder to write into (that's the author's own tooltip, and it's accurate: a directory, not a file).
    • filename_prefix - the base name before the number. Leave it empty and it just numbers the files.
    • image_type - png, png_16bit, or exr. The exr option is the precision play: it converts the image from sRGB to linear before writing, so you get the float data, not the display encoding.

    You can even feed it a prompt with no image and it will still write the .txt - handy for logging what you ran.

    Install

    It ships in spacepxl's ComfyUI-HQ-Image-Save pack. Through ComfyUI Manager, search for ComfyUI-HQ-Image-Save and hit install, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/spacepxl/ComfyUI-HQ-Image-Save
    

    Then restart ComfyUI. Dependencies are just imageio and opencv-python (auto-installed by Manager; on Windows Portable you can run install.bat to hit the embedded Python). No model files, no API keys.

    Where people get burned

    The counter scans the highest numbered file matching your prefix. If you change the prefix, it starts counting from zero again in the same folder - and because it's a scan-and-increment, it won't notice or stop you. Also, the zero_padding only pads the new number; change it mid-run and you get ragged filenames like 00005 next to 000006. Pick your padding once and leave it.

    For the other half of the loop - reading these pairs back - use the pack's LoadImageAndPrompt node, which pulls the image and its .txt sidecar back into the graph. Save here, load there, and you've got a training-data pipeline with no Python.

    CategoryHQ-Image-Save

    Inputs (7)

    NameTypeDefaultDescription
    filepathSTRINGfolder pathThe folder to write in
    filename_prefixSTRING
    zero_paddingINT5
    image_typeCOMBOpng3 options: png, png_16bit, exr
    imageoptIMAGE
    alphaoptMASK
    promptoptSTRING

    Outputs (0)

    No outputs