ComfyUI Node

Save Image Pair Text

Save an Image and Its Caption Together, as a Ready Dataset Pair

By Tlant·Created 2 years ago·Updated 5 months ago· 2
Save Image Pair Text
  • image
    pathD:/ComfyUI/output
    filenameimage.png
    prefix
    suffix
    text

    Most of the time you save an image and its prompt separately and re-pair them later by hand. This node removes that chore: it saves the image and a same-named .txt file with whatever caption you give it, in one shot. That image.png + image.txt layout is the standard folder format that LoRA/dataset tools (and a lot of fine-tune scripts) expect, so if you're building a training set out of generated images - say, generating 200 style-consistent images and captioning them as you go - this is the node that makes the folder come out right.

    How it works

    Feed it an IMAGE tensor, a destination folder, a base filename, optional prefix/suffix, and the text to save. It splits the extension off the filename, writes the image via PIL, and - only if text is non-empty - writes a matching .txt with the same base name. Batches are handled properly: for a multi-frame tensor, each frame gets an eight-digit index appended (image_00000000.png, image_00000001.png, …) so a batch never overwrites itself. The output directory is created on the fly if it doesn't exist. It's an output node (OUTPUT_NODE = True), so it returns nothing and exists purely for its side effect on disk.

    Inputs

    • image - the IMAGE tensor to save.
    • path - output folder. Note the default is Windows-flavored: D:/ComfyUI/output. On Linux/macOS, change it.
    • filename - base name including extension (default image.png).
    • prefix / suffix - inserted before/after the base name (prefixbasesuffix.png).
    • text - the caption; empty text means no .txt is written.

    Install

    Standard pack install:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Tlant/ComfyUI-OllamaPromptsGeneratorTlant
    

    restart, or find "Save Image Pair Text" in ComfyUI Manager.

    Where people get burned

    • The default path is a Windows path. On anything else it'll happily create a D:/ directory structure that makes no sense. Set path to something real before your first run.
    • Filename includes the extension. It's image.png, not image - the node splits the extension itself, so typing .png in the filename is correct, and typing it in both filename and suffix gives you image.png.png.
    • Empty text means no caption file. If you want a .txt on every image, you must supply non-empty text. For training-data generation that's usually fine because you're captioning as you go, but it's a silent behavior worth knowing.

    It's a dataset-assembly node, not a fancy one - but it turns "generate then organize" into one step, and for anyone building a custom training folder out of ComfyUI output, that's the whole ballgame.

    Categoryimage

    Inputs (6)

    NameTypeDefaultDescription
    imageIMAGE
    pathSTRINGD:/ComfyUI/output
    filenameSTRINGimage.png
    prefixSTRING
    suffixSTRING
    textSTRING

    Outputs (0)

    No outputs