How AUTOMATIC1111 Saves Generation Parameters: PNG and EXIF Metadata System Explained
AUTOMATIC1111 embeds complete generation parameters—including prompts, seeds, samplers, and model settings—directly into image files using format-specific metadata containers, enabling exact reproduction of images through the PNG Info tab.
The AUTOMATIC1111/stable-diffusion-webui repository implements a reversible metadata pipeline that stores generation infotext inside PNG chunks, EXIF tags, and GIF comments. This system eliminates the need for separate text files by bundling all parameters required to recreate an image within the image file itself. Understanding this PNG and EXIF metadata system is essential for archiving, sharing, and reproducing AI-generated artwork.
Core Architecture of the Metadata System
The metadata workflow operates through four distinct stages controlled by specific modules in the codebase.
Toggle: Enabling Metadata Writing
Users control the feature through the "Write infotext to metadata of the generated image" setting. This boolean flag is defined in modules/shared_options.py (lines 347-353) and accessed at runtime via shared.opts.enable_pnginfo. When disabled, the pipeline skips all metadata embedding steps entirely.
Generation: Creating the Infotext String
When saving begins, modules/processing.create_infotext (lines 705-735) constructs a human-readable block containing the prompt, negative prompt, seed, sampler name, CFG scale, steps, model hash, and VAE. This function returns a formatted string passed as the info argument to saving routines.
Persistence: Writing Format-Specific Metadata
The modules/images.save_image_with_geninfo function (lines 665-702) handles the actual embedding using different strategies per file format:
- PNG: Stores data in a
PngInfodictionary under the key "parameters" (configurable viapnginfo_section_name), written as a text chunk using Pillow'simage.save(..., pnginfo=...). - JPEG / WebP / AVIF: Encodes the string as an EXIF UserComment tag using the
piexiflibrary. - GIF: Inserts the data into the GIF comment chunk via Pillow's
comment=parameter.
Retrieval: Reading Metadata Back
When users drag images into the PNG Info tab, modules.extras.run_pnginfo invokes modules/images.read_info_from_image (lines 777-818). This function extracts the "parameters" field from PNG chunks, decodes EXIF UserComment tags, or reads GIF comments, while stripping irrelevant keys defined in IGNORED_INFO_KEYS.
The Complete Saving Pipeline
The journey from generation parameters to embedded metadata follows a precise execution path through the image processing stack.
First, modules.processing.process_images triggers the save sequence by calling modules.images.save_image. This function initializes a FilenameGenerator to determine the output path and prepares a pnginfo dictionary containing any extra metadata from scripts or extensions.
Next, the infotext string joins the dictionary under the default key "parameters". The system then creates an ImageSaveParams object, allowing scripts to modify save parameters before _atomically_save_image receives the final configuration.
Finally, _atomically_save_image delegates to save_image_with_geninfo, which branches based on file extension:
# Conceptual flow from modules/images.py
if extension == 'png':
pnginfo = PngInfo()
pnginfo.add_text("parameters", generation_info_string)
image.save(path, pnginfo=pnginfo)
elif extension in ('jpg', 'jpeg', 'webp', 'avif'):
exif_bytes = piexif.dump({
"Exif": {piexif.ExifIFD.UserComment:
piexif.helper.UserComment.dump(generation_info_string)}
})
image.save(path, exif=exif_bytes)
elif extension == 'gif':
image.save(path, comment=generation_info_string)
Reading and Parsing Embedded Parameters
The extraction process reverses the writing logic while sanitizing the output. When read_info_from_image processes an uploaded file, it performs the following operations:
- Copies Pillow's
image.infodictionary for PNG files, or extracts EXIF data for JPEG/WebP/AVIF usingpiexif. - Retrieves the value associated with the "parameters" key (PNG) or decodes the UserComment tag (EXIF formats).
- Filters out technical metadata keys listed in
IGNORED_INFO_KEYSto present only generation-relevant data. - Returns a tuple
(geninfo, items)wheregeninfocontains the full parameter string anditemsholds remaining metadata chunks.
The UI layer in modules/ui.py (lines 874-892) and modules/extras.py (lines 16-37) renders this data in the PNG Info tab and provides the Paste button functionality that repopulates the prompt interface via modules.infotext_utils.parse_generation_parameters.
Practical Code Examples
Saving an image with metadata:
from modules import processing, images
# Generate the infotext block
info = processing.create_infotext(p, prompts, seeds, subseeds)
# Save with embedded parameters
full_path, txt_path = images.save_image(
image=image,
path=out_dir,
basename=basename,
seed=p.seed,
prompt=p.prompt,
extension='png',
info=info, # Stored under 'parameters' key
p=p
)
Reading metadata from an existing image:
from modules import images
# Extract generation parameters
geninfo, items = images.read_info_from_image(uploaded_image)
# geninfo now contains the full parameter string:
# "Steps: 20, Sampler: DPM++ 2M Karras, CFG scale: 7, Seed: 12345, ..."
Summary
- AUTOMATIC1111 stores generation parameters directly inside image files using the
enable_pnginfosetting defined inmodules/shared_options.py. - The
create_infotextfunction inmodules/processing.pybuilds the parameter string, whilemodules/images.pyhandles format-specific embedding viasave_image_with_geninfo. - PNG files use text chunks with the key "parameters", JPEG/WebP/AVIF use EXIF UserComment tags via
piexif, and GIF uses comment blocks. - The
read_info_from_imagefunction inmodules/images.pyextracts and sanitizes this data for the PNG Info tab, enabling exact reproduction of generated images.
Frequently Asked Questions
How do I disable metadata embedding in AUTOMATIC1111?
Navigate to Settings > Saving images/grids and uncheck "Write infotext to metadata of the generated image". This sets shared.opts.enable_pnginfo to False, causing the pipeline to skip all metadata writing operations while still saving the image file.
What is the difference between PNG Info and EXIF metadata in this context?
PNG Info refers to text chunks embedded within PNG files using Pillow's PngInfo class, specifically under the "parameters" key. EXIF metadata applies to JPEG, WebP, and AVIF formats, where the same generation string is stored in the UserComment tag using the piexif library. Both contain identical generation parameters but use format-specific storage mechanisms.
Can I extract generation parameters from images created by other Stable Diffusion interfaces?
Yes, provided they use compatible metadata formats. AUTOMATIC1111's read_info_from_image function searches for the "parameters" text chunk in PNGs or the UserComment EXIF tag in other formats. If the other interface stores data in these standard locations using the same key names, the PNG Info tab will successfully parse and display the parameters.
Where is the metadata actually stored inside the image file?
For PNG files, the data resides in a tEXt or zTXt chunk with the keyword "parameters". For JPEG/WebP/AVIF, it lives in the EXIF segment under the UserComment tag (ExifIFD 0x9286). For GIF files, the data occupies the comment sub-block. You can verify this using external tools like exiftool or pngcheck to inspect these specific metadata containers.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →