Use one counter across full save path
This commit is contained in:
+20
-4
@@ -136,6 +136,20 @@ def _next_counter(directory, filename_template):
|
||||
return highest + 1
|
||||
|
||||
|
||||
def _next_counter_for_relative_path(base_directory, relative_template):
|
||||
os.makedirs(base_directory, exist_ok=True)
|
||||
if "%counter%" not in relative_template:
|
||||
return 1
|
||||
|
||||
counter = 1
|
||||
while True:
|
||||
candidate = relative_template.replace("%counter%", str(counter).zfill(3))
|
||||
full_path = os.path.join(base_directory, *[part for part in candidate.split("/") if part])
|
||||
if not os.path.exists(full_path):
|
||||
return counter
|
||||
counter += 1
|
||||
|
||||
|
||||
def _build_pnginfo(prompt=None, extra_pnginfo=None):
|
||||
try:
|
||||
pnginfo = Image.PngImagePlugin.PngInfo()
|
||||
@@ -362,11 +376,13 @@ class DumasSaveImageNode:
|
||||
for batch_index in range(images.shape[0]):
|
||||
frame_pattern = resolved_pattern.replace("%batch_num%", str(batch_index))
|
||||
frame_parts = [part for part in frame_pattern.split("/") if part]
|
||||
sub_dirs = frame_parts[:-1]
|
||||
filename_template = (frame_parts[-1] if frame_parts else "image_%counter%") + extension
|
||||
relative_template = "/".join(frame_parts[:-1] + [((frame_parts[-1] if frame_parts else "image_%counter%") + extension)])
|
||||
counter = _next_counter_for_relative_path(target_dir, relative_template)
|
||||
resolved_relative = relative_template.replace("%counter%", str(counter).zfill(3))
|
||||
resolved_parts = [part for part in resolved_relative.split("/") if part]
|
||||
sub_dirs = resolved_parts[:-1]
|
||||
filename = resolved_parts[-1] if resolved_parts else f"image_{str(counter).zfill(3)}{extension}"
|
||||
frame_dir = os.path.join(target_dir, *sub_dirs)
|
||||
counter = _next_counter(frame_dir, filename_template)
|
||||
filename = filename_template.replace("%counter%", str(counter).zfill(3))
|
||||
image = _tensor_image_to_pil_image(images[batch_index : batch_index + 1])
|
||||
full_path = os.path.join(frame_dir, filename)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user