Skip to content

Instantly share code, notes, and snippets.

@un1tz3r0
Created September 30, 2022 05:14
Show Gist options
  • Save un1tz3r0/3ef176e014b5c0636b1971aed60f82cb to your computer and use it in GitHub Desktop.
Save un1tz3r0/3ef176e014b5c0636b1971aed60f82cb to your computer and use it in GitHub Desktop.
Example of how to extract prompt and seed (and other parameters) from PNG files generated by stablediffusion
import png, pathlib
def getpngmetadata(filename):
d = {}
with open(filename, "rb") as fh:
try:
for chnk in png.Reader(fh).chunks():
if chnk[0] == b'tEXt' and b'\x00' in chnk[1]:
k, v = chnk[1].split(b'\x00', 1)
d[k] = v
except:
pass
return d
for fn in pathlib.Path("out/Default").glob("*.png"):
md = getpngmetadata(str(fn))
if len(md) > 0:
print(f"{fn}: {repr(md)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment