Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more placeholders for file/folder name customization #16

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,23 @@ If you don't have *ComfyUI-Manager*, then:

![Screenshot 2023-08-17 at 13 15 18](https://github.com/giriss/comfy-image-saver/assets/2811408/785f2475-8f9a-45c9-9d38-855161a98495)

## Customization of file/folder names

You can use following placeholders:

- `%date`
- `%seed`
- `%counter`
- `%sampler_name`
- `%steps`
- `%cfg`
- `%scheduler`
- `%time` *– format taken from `time_format`*
- `%model` *– full name of model file*
- `%basemodelname` *– name of model (without file extension)*

Example:

| `filename` value | Result file name |
| --- | --- |
| `%time-%basemodelname-%cfg-%steps-%sampler_name-%scheduler-%seed` | `2023-11-16-131331-Anything-v4.5-pruned-mergedVae-7.0-25-dpm_2-normal-1_01.png` |
100 changes: 92 additions & 8 deletions nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,55 @@ def get_timestamp(time_format):
return timestamp


def make_pathname(filename, seed, modelname, counter, time_format):
def make_pathname(
filename,
seed,
modelname,
counter,
time_format,
sampler_name,
steps,
cfg,
scheduler,
basemodelname,
):
filename = filename.replace("%date", get_timestamp("%Y-%m-%d"))
filename = filename.replace("%time", get_timestamp(time_format))
filename = filename.replace("%model", modelname)
filename = filename.replace("%seed", str(seed))
filename = filename.replace("%counter", str(counter))
filename = filename.replace("%sampler_name", sampler_name)
filename = filename.replace("%steps", str(steps))
filename = filename.replace("%cfg", str(cfg))
filename = filename.replace("%scheduler", scheduler)
filename = filename.replace("%basemodelname", basemodelname)
return filename


def make_filename(filename, seed, modelname, counter, time_format):
filename = make_pathname(filename, seed, modelname, counter, time_format)
def make_filename(
filename,
seed,
modelname,
counter,
time_format,
sampler_name,
steps,
cfg,
scheduler,
basemodelname,
):
filename = make_pathname(
filename,
seed,
modelname,
counter,
time_format,
sampler_name,
steps,
cfg,
scheduler,
basemodelname,
)

return get_timestamp(time_format) if filename == "" else filename

Expand Down Expand Up @@ -209,12 +247,58 @@ def INPUT_TYPES(cls):

CATEGORY = "ImageSaverTools"

def save_files(self, images, seed_value, steps, cfg, sampler_name, scheduler, positive, negative, modelname, quality_jpeg_or_webp,
lossless_webp, width, height, counter, filename, path, extension, time_format, prompt=None, extra_pnginfo=None):
filename = make_filename(filename, seed_value, modelname, counter, time_format)
path = make_pathname(path, seed_value, modelname, counter, time_format)
ckpt_path = folder_paths.get_full_path("checkpoints", modelname)
def save_files(
self,
images,
seed_value,
steps,
cfg,
sampler_name,
scheduler,
positive,
negative,
modelname,
quality_jpeg_or_webp,
lossless_webp,
width,
height,
counter,
filename,
path,
extension,
time_format,
prompt=None,
extra_pnginfo=None,
):
basemodelname = parse_name(modelname)

filename = make_filename(
filename,
seed_value,
modelname,
counter,
time_format,
sampler_name,
steps,
cfg,
scheduler,
basemodelname,
)

path = make_pathname(
path,
seed_value,
modelname,
counter,
time_format,
sampler_name,
steps,
cfg,
scheduler,
basemodelname,
)

ckpt_path = folder_paths.get_full_path("checkpoints", modelname)
modelhash = calculate_sha256(ckpt_path)[:10]
comment = f"{handle_whitespace(positive)}\nNegative prompt: {handle_whitespace(negative)}\nSteps: {steps}, Sampler: {sampler_name}{f'_{scheduler}' if scheduler != 'normal' else ''}, CFG Scale: {cfg}, Seed: {seed_value}, Size: {width}x{height}, Model hash: {modelhash}, Model: {basemodelname}, Version: ComfyUI"
output_path = os.path.join(self.output_dir, path)
Expand Down