Created
September 30, 2022 05:14
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
png |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment