2022-09-16 17:09:04 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import json
|
2023-03-04 01:19:37 +00:00
|
|
|
from invokeai.backend.image_util import retrieve_metadata
|
2022-09-16 17:09:04 +00:00
|
|
|
|
|
|
|
if len(sys.argv) < 2:
|
|
|
|
print("Usage: file2prompt.py <file1.png> <file2.png> <file3.png>...")
|
2022-10-08 15:37:23 +00:00
|
|
|
print("This script opens up the indicated invoke.py-generated PNG file(s) and prints out their metadata.")
|
2022-09-16 17:09:04 +00:00
|
|
|
exit(-1)
|
|
|
|
|
|
|
|
filenames = sys.argv[1:]
|
|
|
|
for f in filenames:
|
|
|
|
try:
|
|
|
|
metadata = retrieve_metadata(f)
|
2022-09-16 20:58:16 +00:00
|
|
|
print(f'{f}:\n',json.dumps(metadata['sd-metadata'], indent=4))
|
2022-09-16 17:09:04 +00:00
|
|
|
except FileNotFoundError:
|
|
|
|
sys.stderr.write(f'{f} not found\n')
|
|
|
|
continue
|
|
|
|
except PermissionError:
|
|
|
|
sys.stderr.write(f'{f} could not be opened due to inadequate permissions\n')
|
|
|
|
continue
|