Add EXIF info containing parameters to outputs
EXIF code based on https://github.com/lstein/stable-diffusion, but with more info than just the prompt. This will help users view the parameters they used in the future.
Downside: Many online image sharing platforms (including Discord and reddit) strip EXIF info from images in order to protect people's privacy, since many cameras embed GPS info into EXIF data as well. This means that the parameters used can't be easily shared to other people with this method.
I have made something similar, using IPTC (with https://github.com/james-see/iptcinfo3), but saving all parameters (even argv[0]) in the "caption/abstract", so you could copy and paste it into the command prompt to run it. Snippet:
parser.add_argument("--iptc", type=bool, nargs="?", default=True, help="save IPTC data to output image (only for JPG)")
# ...
fn = os.path.join(sample_path, "seed_" + str(opt.seed) + "_" + f"{base_count:05}.{opt.format}")
Image.fromarray(x_sample.astype(np.uint8)).save(
fp = fn,
quality = 95,
)
if opt.iptc and opt.format == "jpg":
info = IPTCInfo(fn, force=True)
cmd = " ".join([f'"{x}"' if " " in x else x for x in sys.argv])
info["caption/abstract"] = f"{cmd}{f' --seed {opt.seed}' if '--seed' not in cmd else ''}"[:2000]
info["supplemental category"] = ["stable diffusion"]
info.save(options="overwrite")
Result (as seen in Irfanview):

I wonder if using this format (reproducing exactly how the parameters are used in the input of the program) would be better, because it would make it easier to reproduce the original image (instead of doing a lot of copy-and-paste and editing)...
Some comments to this:
- I think it is quite important to add this
- This should also be added for the gradio stuff
- PNGInfo will not work on jpeg files which are an option in the gradio scripts
Also, possibly using iTXT might be better since it supports UTF-8