diff options
author | AUTOMATIC <16777216c@gmail.com> | 2022-10-14 15:15:03 +0000 |
---|---|---|
committer | AUTOMATIC <16777216c@gmail.com> | 2022-10-14 15:15:03 +0000 |
commit | 0aec19d7837d8564355fdb286541db7165852e41 (patch) | |
tree | 3befe3e678e2005a8965b96d2dec2460dc25a805 /modules/images.py | |
parent | 33ae6be55eaedabd49c8c888ec0b37c612618fdf (diff) | |
download | stable-diffusion-webui-gfx803-0aec19d7837d8564355fdb286541db7165852e41.tar.gz stable-diffusion-webui-gfx803-0aec19d7837d8564355fdb286541db7165852e41.tar.bz2 stable-diffusion-webui-gfx803-0aec19d7837d8564355fdb286541db7165852e41.zip |
make pasting into img2img prompt work
make image params request not use temp files
Diffstat (limited to 'modules/images.py')
-rw-r--r-- | modules/images.py | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/modules/images.py b/modules/images.py index f1155b7f..68cdbc93 100644 --- a/modules/images.py +++ b/modules/images.py @@ -1,4 +1,5 @@ import datetime
+import io
import math
import os
from collections import namedtuple
@@ -465,21 +466,20 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i return fullfn, txt_fullfn
-def image_data(image_path):
- file, ext = os.path.splitext(image_path.name)
- data = {}
- if "png" in ext:
- image = Image.open(image_path.name, "r")
- print(f"Image data requested for {image_path.name} {image.format} of {type(image)}")
- try:
- data = image.text["parameters"]
- except Exception as e:
- print(f"Exception: {e}")
- pass
- print(f"Image data: {data}")
- if "txt" in ext:
- myfile = open(image_path.name, 'r')
- data = myfile.read()
- myfile.close()
-
- return data, None
+def image_data(data):
+ try:
+ image = Image.open(io.BytesIO(data))
+ textinfo = image.text["parameters"]
+ return textinfo, None
+ except Exception:
+ pass
+
+ try:
+ text = data.decode('utf8')
+ assert len(text) < 10000
+ return text, None
+
+ except Exception:
+ pass
+
+ return '', None
|