aboutsummaryrefslogtreecommitdiff
path: root/modules/images.py
diff options
context:
space:
mode:
authorw-e-w <40751091+w-e-w@users.noreply.github.com>2023-09-06 20:24:26 +0900
committerw-e-w <40751091+w-e-w@users.noreply.github.com>2023-09-06 20:24:26 +0900
commit35d1c94549cf75e7e312372d90fee0acc2806426 (patch)
tree8d9a6e76031e6f6c4f5750dbc94b459c82a7855b /modules/images.py
parentbd9b3d15e8f631f9475d14a5fd07560c177dc2f3 (diff)
save_images_add_number_suffix
Diffstat (limited to 'modules/images.py')
-rw-r--r--modules/images.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/modules/images.py b/modules/images.py
index eb644733..10dcd9ab 100644
--- a/modules/images.py
+++ b/modules/images.py
@@ -661,7 +661,15 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i
save_image_with_geninfo(image_to_save, info, temp_file_path, extension, existing_pnginfo=params.pnginfo, pnginfo_section_name=pnginfo_section_name)
- os.replace(temp_file_path, filename_without_extension + extension)
+ full_file_name = filename_without_extension + extension
+ if shared.opts.save_images_add_number_suffix and os.path.exists(full_file_name):
+ count = 1
+ while True:
+ full_file_name = f"{filename_without_extension}_{count}{extension}"
+ if not os.path.exists(full_file_name):
+ break
+ count += 1
+ os.replace(temp_file_path, full_file_name)
fullfn_without_extension, extension = os.path.splitext(params.filename)
if hasattr(os, 'statvfs'):