Setting custom filenames in Stable Diffusion – Comfyui and Automatic1111 webui

The Stable Diffusion ComfyUI is a powerful GUI for AI image generation, but it’s also known for its limited documentation and steep learning curve for automatic1111 users.

By default, ComfyUI generated images will be dumped in the output folder with the meaningless filename ComfyUI_00001_.png with increasing numbers.

Setting custom filenames in ComfyUI workflow

  1. Right-click your Save Image node and select convert filename_prefix to widget.
  2. Add a Primitive node (Add Node > advanced > Primitive)
  3. Connect the Save Image node filename_prefix value to your Primitive node endopint.
  4. In this primitive node you can now set the output filename in the format specified in the manual, for example: %date:yyyy-MM-dd%/%date:hhmmss%_%KSampler.seed% to save files in a subfolder named with the current date.

Sample format strings

output/date/time_seed_number.png  %date:yyyy-MM-dd%/%date:hhmmss%_%KSampler.seed%

You can insert the image resolution to its filename as follows:

output/date/seed/widthxheight_number.png  %date:yyyy-MM-dd%/%KSampler.seed%/%Empty Latent Image.width%x%Empty Latent Image.height%

You can also add a value from any node in the format %NodeName.node_value%.

Format like automatic1111 webui

Notice this is not the exact same format, because in auto1111 the filename begins with its generation number, ensuring they are sorted by generation. In Comfy, the generation number is inserted at the end and this cannot be changed.

output/date/seed_number.png  %date:yyyy-MM-dd%/%KSampler.seed%

Make sort by name also sort by generation number by prepending the time to the name:

output/date/time_seed_number.png  %date:yyyy-MM-dd%/%date:hhmmss%_%KSampler.seed%

By adding the current time (%date:hhmmss%) to the beginning of the filename, sorting the folder by name will show the files in the same order they were created.

Leave a Reply

Your email address will not be published. Required fields are marked *