Save Image With Text
Assemble a LoRA dataset without leaving ComfyUI
- image
- image_path
- text_path
Dataset prep is the unglamorous half of LoRA training, and it's where most people burn the most time. Trainers want image/caption pairs sitting next to each other - 1.png and 1.txt - with matching names, and the usual flow is: generate images, save them, tag them in a separate tool, then manually pair the filenames. Save Image With Text collapses that into one node: give it an image and a caption string, and it writes both files with matching names into your output folder. That's the whole sell.
Why you'd reach for it
Dataset curation beats every training knob, and captioning is the most impact-per-hour step of it (the KB's LoRA-training doc leans hard on this). For the Danbooru-tagged anime lineage, the play is WD14-style tags; for LLM-encoder models it's JoyCaption/Florence-2-style captions. Wherever your captions come from, they have to end up as .txt siblings of the images - and that's the mechanical, error-prone bit this node removes. Build it into a generation workflow, feed your tagger or caption node into text, and every queue run lands a properly paired dataset entry.
How it works
On each run it takes the first frame of the incoming image, resolves the next free filename in your target folder, writes the .txt first, then the .png (moderate PNG compression, perfectly fine for training inputs). Filename numbering is automatic and based on what's already in the folder:
- With a
prefix: files come outprefix_1,prefix_2, ... counting both.pngand.txtas one unit. - Without a
prefix: plain1,2, ... - the layout most kohya/ai-toolkit-style trainers expect out of the box.
Inputs and outputs
- image - the image to save (batch: only the first frame is written).
- text - the caption, written verbatim to the sibling
.txt. - dir_path - destination folder relative to ComfyUI's output directory.
training/my_loralands inComfyUI/output/training/my_lora. The folder is created if it doesn't exist. - prefix - optional filename prefix; auto-incrementing index is appended.
Two outputs, both relative paths: image_path (the .png) and text_path (the .txt). Those are handy if you're passing file locations to another node downstream.
Installation
This node ships in ComfyUI-Alchemine-Pack, in the Lora group - which the README labels experimental, so don't be surprised if it evolves. Install via ComfyUI Manager (search "Alchemine") and restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/alchemine/comfyui-alchemine-pack
pip install -r requirements.txt
Then restart ComfyUI. Nothing heavy here: the pack's only dependency is python-dotenv, and this node just needs Pillow/numpy, which ComfyUI already brings.
Common issues
Two things trip people up. First, numbering is append-based, not overwrite-based - rerun a queue and you get prefix_3, prefix_4, not a fresh folder. If you want a clean dataset, clear the target directory between runs (or use a fresh dir_path per batch). Second, the dir_path is output-relative, so if you type an absolute path it won't resolve the way you expect. And since only the first frame of a batch gets saved, if you're saving batched generations you'll want one image per run or an unpack node ahead of this one. None of these are bugs - they're just the shape of a node built for looping one image at a time into a dataset.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| text | STRING | — | |
| dir_path | STRING | — | |
| prefix | STRING | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image_path | STRING | — |
| text_path | STRING | — |