Advertisement
Eliont

PngData

May 3rd, 2024
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | Source Code | 0 0
  1. import os
  2. from PIL import Image
  3. import time
  4. import codecs
  5.  
  6. input_folder = 'E:\\SD'
  7.  
  8. prompts = []
  9. for path, subdirs, files in os.walk(input_folder):
  10.   for name in files:
  11.     filename = os.path.join(path, name)
  12.     print (filename)
  13.     if filename.endswith('.png'):
  14.       # Open the image file with PIL.Image.File
  15.       try:
  16.         im = Image.open(filename)
  17.       except:
  18.         continue
  19.      
  20.       if 'parameters' in im.info:
  21.         metadata_str = str(im.info['parameters'].split('Negative prompt')[0])
  22.  
  23.         # print (metadata_str)
  24.         # time.sleep(1)
  25.                
  26.         if len(metadata_str.split(',')) > 1 and metadata_str not in prompts:
  27.           prompts.append(metadata_str)
  28.            
  29.           with codecs.open("prompts.txt", "a", encoding='utf-8') as myfile:
  30.             myfile.write(metadata_str.replace('_',' '))
  31.             myfile.write("\n")
  32.  
  33.       im.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement