stable-diffusion icon indicating copy to clipboard operation
stable-diffusion copied to clipboard

Add EXIF info containing parameters to outputs

Open TapuCosmo opened this issue 3 years ago • 3 comments

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.

TapuCosmo avatar Aug 26 '22 02:08 TapuCosmo

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): image

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)...

AltoRetrato avatar Sep 08 '22 22:09 AltoRetrato

Some comments to this:

  1. I think it is quite important to add this
  2. This should also be added for the gradio stuff
  3. PNGInfo will not work on jpeg files which are an option in the gradio scripts

veni-vidi-code avatar Sep 09 '22 11:09 veni-vidi-code

Also, possibly using iTXT might be better since it supports UTF-8

veni-vidi-code avatar Sep 09 '22 11:09 veni-vidi-code