feat: add overwrite/increment to SaveImageTextDataSetToFolderNode (#13215)
Some checks are pending
Python Linting / Run Ruff (push) Waiting to run
Python Linting / Run Pylint (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.10, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.11, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.12, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-unix-nightly (12.1, , linux, 3.11, [self-hosted Linux], nightly) (push) Waiting to run
Execution Tests / test (macos-latest) (push) Waiting to run
Execution Tests / test (ubuntu-latest) (push) Waiting to run
Execution Tests / test (windows-latest) (push) Waiting to run
Test server launches without errors / test (push) Waiting to run
Unit Tests / test (macos-latest) (push) Waiting to run
Unit Tests / test (ubuntu-latest) (push) Waiting to run
Unit Tests / test (windows-2022) (push) Waiting to run

This commit is contained in:
Charles Chan 2026-05-29 01:12:04 +08:00 committed by GitHub
parent cffa2f43aa
commit 6ceec29bd1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -157,7 +157,7 @@ class LoadImageTextDataSetFromFolderNode(io.ComfyNode):
return io.NodeOutput(output_tensor, captions) return io.NodeOutput(output_tensor, captions)
def save_images_to_folder(image_list, output_dir, prefix="image"): def save_images_to_folder(image_list, output_dir, prefix="image", overwrite=True):
"""Utility function to save a list of image tensors to disk. """Utility function to save a list of image tensors to disk.
Args: Args:
@ -197,7 +197,11 @@ def save_images_to_folder(image_list, output_dir, prefix="image"):
raise ValueError(f"Expected torch.Tensor, got {type(img_tensor)}") raise ValueError(f"Expected torch.Tensor, got {type(img_tensor)}")
# Save image # Save image
filename = f"{prefix}_{idx:05d}.png" if overwrite:
filename = f"{prefix}_{idx:05d}.png"
else:
_, _, counter, _, resolved_prefix = folder_paths.get_save_image_path(prefix, output_dir)
filename = f"{resolved_prefix}_{counter:05}_{idx:05d}.png"
filepath = os.path.join(output_dir, filename) filepath = os.path.join(output_dir, filename)
img.save(filepath) img.save(filepath)
saved_files.append(filename) saved_files.append(filename)
@ -230,19 +234,26 @@ class SaveImageDataSetToFolderNode(io.ComfyNode):
tooltip="Prefix for saved image filenames.", tooltip="Prefix for saved image filenames.",
advanced=True, advanced=True,
), ),
io.Combo.Input(
"mode",
default="overwrite",
options=["overwrite", "increment"],
tooltip="Whether to overwrite existing files or increment filenames to avoid overwriting."
),
], ],
outputs=[], outputs=[],
is_deprecated=True, # This node is redundant and superseded by existing Save Image nodes where the target folder can be specified in the filename_prefix is_deprecated=True, # This node is redundant and superseded by existing Save Image nodes where the target folder can be specified in the filename_prefix
) )
@classmethod @classmethod
def execute(cls, images, folder_name, filename_prefix): def execute(cls, images, folder_name, filename_prefix, mode):
# Extract scalar values # Extract scalar values
folder_name = folder_name[0] folder_name = folder_name[0]
filename_prefix = filename_prefix[0] filename_prefix = filename_prefix[0]
mode = mode[0]
output_dir = os.path.join(folder_paths.get_output_directory(), folder_name) output_dir = os.path.join(folder_paths.get_output_directory(), folder_name)
saved_files = save_images_to_folder(images, output_dir, filename_prefix) saved_files = save_images_to_folder(images, output_dir, filename_prefix, mode=='overwrite')
logging.info(f"Saved {len(saved_files)} images to {output_dir}.") logging.info(f"Saved {len(saved_files)} images to {output_dir}.")
return io.NodeOutput() return io.NodeOutput()
@ -278,18 +289,25 @@ class SaveImageTextDataSetToFolderNode(io.ComfyNode):
tooltip="Prefix for saved image filenames.", tooltip="Prefix for saved image filenames.",
advanced=True, advanced=True,
), ),
io.Combo.Input(
"mode",
default="overwrite",
options=["overwrite", "increment"],
tooltip="Whether to overwrite existing files or increment filenames to avoid overwriting."
),
], ],
outputs=[], outputs=[],
) )
@classmethod @classmethod
def execute(cls, images, folder_name, filename_prefix, texts=None): def execute(cls, images, folder_name, filename_prefix, mode, texts=None):
# Extract scalar values # Extract scalar values
folder_name = folder_name[0] folder_name = folder_name[0]
filename_prefix = filename_prefix[0] filename_prefix = filename_prefix[0]
mode = mode[0]
output_dir = os.path.join(folder_paths.get_output_directory(), folder_name) output_dir = os.path.join(folder_paths.get_output_directory(), folder_name)
saved_files = save_images_to_folder(images, output_dir, filename_prefix) saved_files = save_images_to_folder(images, output_dir, filename_prefix, mode=='overwrite')
# Save captions # Save captions
if texts: if texts: