ComfyUI Extension: comfyui-save-image-enhanced
enable to save the image without the default filename suffix, with the feature of saving caption txt file to save prompts or descriptions of the image.
Custom Nodes (0)
README
Save Image Enhanced Node for ComfyUI
A powerful and user-friendly custom node for ComfyUI, designed to provide enhanced control over image saving. Inspired by the flexibility found in projects like WAS Node Suite and the innovation of Divergent Nodes, this node offers advanced filename handling and output options.
Features
- Flexible Filename Prefixes: Use dynamic placeholders like
%date:yyyy-MM-dd%
,%width%
,%height%
, and even values from other connected nodes (e.g.,%Empty Latent Image.width%
) directly in your filename prefix. Supports%batch_num%
for batch processing. - Custom Output Folders: Save images to a subfolder within ComfyUI's main output directory or specify an absolute path anywhere on your system.
- Smart Counter Suffix: Automatically append an incrementing numerical suffix (e.g.,
_00001_
) to prevent overwriting existing files. The padding (number of digits) of this counter is now fully customizable (from 1 to 9 digits). - Intelligent Filename Increment (New!): A unique
allow_overwrite
toggle allows you to automatically increment the entirefilename_prefix
if a file with that name exists. For example, if000.png
exists, the next run will save as001.png
,002.png
, and so on, without needing to change node inputs. This works for any prefix ending in a number. - Caption Saving: Optionally save a text caption alongside each image, using a configurable file extension (default
.txt
). - PNG Metadata Support: Embed workflow metadata (prompt, extra PNG info) directly into the saved PNG files, just like the standard Save Image node.
- Robust Error Handling: Includes filename sanitization to prevent OS errors and UTF-8 encoding for captions and metadata.
Installation
- Navigate to your ComfyUI installation directory.
- Go to the
custom_nodes
folder. - Clone this repository:
git clone https://github.com/KY-2000/comfyui-save-image-enhanced.git
- Restart ComfyUI.
Usage Tutorial
1. Add the Node
- In the ComfyUI node browser, search for
Save Image Enhanced (DN)
. - Drag and drop the node into your workflow.
2. Connect Your Image
- Connect the output of an image-generating node (like
KSampler
,VAEDecode
, etc.) to theimages
input of this node.
3. Configure the Node Parameters
-
filename_prefix
(STRING):- This is the base name for your saved files.
- Dynamic Placeholders:
%date:yyyy-MM-dd%
: Inserts the current date (e.g.,2024-06-18
).%date:yyyyMMdd_HHmmss%
: Inserts a detailed timestamp (e.g.,20240618_143022
).%width%
/%height%
: Inserts the width/height of the image.%batch_num%
: Inserts the index of the image within the current batch (0-padded to 5 digits by default logic, but seeadd_counter_suffix
).%NodeID.InputName%
: Inserts the value of an input from another node in your workflow (e.g.,%6.width%
to get the width from node 6).
- Example Prefixes:
my_project_%date:yyyy-MM-dd%
: Saves asmy_project_2024-06-18.png
.character_%width%x%height%_%date:yyyyMMdd_HHmmss%
: Saves ascharacter_512x768_20240618_143022.png
.000
: A simple prefix to be used with theallow_overwrite
feature (see below).
-
output_folder
(STRING):- Specifies where to save the images.
- Relative Path: If not an absolute path, it's treated as a subfolder of ComfyUI's main
output
directory.- Example:
my_images
saves toComfyUI/output/my_images/
.
- Example:
- Absolute Path: Save anywhere on your system.
- Example (Linux/macOS):
/Users/YourName/MyArtwork/
- Example (Windows):
C:\\Users\\YourName\\MyArtwork\\
- Example (Linux/macOS):
- Empty String (
""
): Saves directly to ComfyUI's mainoutput
directory.
-
add_counter_suffix
(BOOLEAN):True
(Default): Appends a counter to the filename to prevent overwrites. The counter value is determined by ComfyUI's standard logic, which looks for an existing counter at the end of thefilename_prefix
.- Example: If
filename_prefix
isimage
andimage.png
doesn't exist, it saves asimage.png
. Ifimage.png
exists, it saves asimage_00001.png
. Ifimage_00001.png
exists, it saves asimage_00002.png
. - Important: If your
filename_prefix
ends with a number (e.g.,image_000
), that number is treated as the starting counter. So ifimage_000.png
doesn't exist, it will save asimage_001.png
.
- Example: If
False
: Does not add a counter suffix. If a file with the exact name exists, it will be overwritten (unlessallow_overwrite=False
).
-
counter_padding
(INT):- Controls the number of digits (1-9) used for the counter suffix added by
add_counter_suffix
. - Default:
5
(produces_00001_
,_00002_
, etc.). - Example (
counter_padding=3
): Produces_001_
,_002_
, etc. - Example (
counter_padding=6
): Produces_000001_
,_000002_
, etc.
- Controls the number of digits (1-9) used for the counter suffix added by
-
allow_overwrite
(BOOLEAN):False
(Default): Enables the Intelligent Filename Increment feature.- Instead of just adding a counter suffix, this feature automatically increments the entire
filename_prefix
if a file with that name already exists. - It works by checking if the file constructed from
filename_prefix
exists. If it does, it tries to find the next available number by parsing the end of thefilename_prefix
. - How to Use: Set your
filename_prefix
to a simple incrementing pattern like000
,img001
, orMyArt_10
. Setadd_counter_suffix=False
. Each time you run the node with the exact same inputs, it will save000.png
, then001.png
, then002.png
, etc. You don't need to manually change the prefix or toggleadd_counter_suffix
to make it increment. This is particularly useful for sequential generation workflows. - Note: For this feature,
add_counter_suffix
should typically beFalse
to avoid conflicting counter logic.
- Instead of just adding a counter suffix, this feature automatically increments the entire
True
: Disables the Intelligent Filename Increment. The node behaves like a standard ComfyUI Save Image node with the addedcounter_padding
option.
-
caption
(STRING - Optional Input):- Connect a text string here to save it as a separate caption file.
- Useful for saving prompts or descriptions alongside images.
-
caption_file_extension
(STRING - Optional):- Sets the file extension for the caption file.
- Default:
.txt
4. Run Your Workflow
- Queue and run your workflow.
- The node will save your images according to the configured settings.
Example Workflows
Basic Save with Date
- Use
filename_prefix
:MyArt_%date:yyyy-MM-dd%_%batch_num%
- Use
output_folder
:generated_images
- This saves files like
ComfyUI/output/generated_images/MyArt_2024-06-18_00001.png
.
Sequential Naming with Intelligent Increment
- Use
filename_prefix
:000
- Use
output_folder
:sequential_runs
- Set
add_counter_suffix
:False
- Set
allow_overwrite
:False
- Run the workflow multiple times. Files will be saved as
ComfyUI/output/sequential_runs/000.png
,001.png
,002.png
, etc.
Custom Counter Padding
- Use
filename_prefix
:test_image
- Set
add_counter_suffix
:True
- Set
counter_padding
:3
- Files will be saved as
test_image_001.png
,test_image_002.png
, etc.
Acknowledgements
This node takes inspiration from the excellent work done by the creators of WAS Node Suite and Divergent Nodes. Their contributions to the ComfyUI community have been invaluable.