aboutsummaryrefslogtreecommitdiffstats
path: root/modules/images.py
diff options
context:
space:
mode:
authorMalumaDev <piano.lu92@gmail.com>2022-10-15 14:20:17 +0000
committerGitHub <noreply@github.com>2022-10-15 14:20:17 +0000
commit7b7561f6e4be3b591d845f14743bac2069e6428e (patch)
treef7ef27ffad7017c0d3cbd9b7a899c4308339885d /modules/images.py
parent37d7ffb415cd8c69b3c0bb5f61844dde0b169f78 (diff)
parentd3ffc962dd1d5c8d0ed763a9d05832c153ff15ea (diff)
downloadstable-diffusion-webui-gfx803-7b7561f6e4be3b591d845f14743bac2069e6428e.tar.gz
stable-diffusion-webui-gfx803-7b7561f6e4be3b591d845f14743bac2069e6428e.tar.bz2
stable-diffusion-webui-gfx803-7b7561f6e4be3b591d845f14743bac2069e6428e.zip
Merge branch 'master' into test_resolve_conflicts
Diffstat (limited to 'modules/images.py')
-rw-r--r--modules/images.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/modules/images.py b/modules/images.py
index c0a90676..b9589563 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
@@ -23,6 +24,10 @@ def image_grid(imgs, batch_size=1, rows=None):
rows = opts.n_rows
elif opts.n_rows == 0:
rows = batch_size
+ elif opts.grid_prevent_empty_spots:
+ rows = math.floor(math.sqrt(len(imgs)))
+ while len(imgs) % rows != 0:
+ rows -= 1
else:
rows = math.sqrt(len(imgs))
rows = round(rows)
@@ -463,3 +468,22 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i
txt_fullfn = None
return fullfn, txt_fullfn
+
+
+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