diff options
author | AUTOMATIC <16777216c@gmail.com> | 2022-11-27 13:28:32 +0000 |
---|---|---|
committer | AUTOMATIC <16777216c@gmail.com> | 2022-11-27 13:28:32 +0000 |
commit | 506d529d19f135f57e142371271f84d4971b456f (patch) | |
tree | 2ce3f9431baa71149afc320eacd6d23118847832 /modules/images.py | |
parent | 488f831d528f538f8c6a801e91d80c5e2ee05cf1 (diff) | |
download | stable-diffusion-webui-gfx803-506d529d19f135f57e142371271f84d4971b456f.tar.gz stable-diffusion-webui-gfx803-506d529d19f135f57e142371271f84d4971b456f.tar.bz2 stable-diffusion-webui-gfx803-506d529d19f135f57e142371271f84d4971b456f.zip |
rework #5012 to also work for pictures dragged into the prompt and also add Clip skip + ENSD to parameters
Diffstat (limited to 'modules/images.py')
-rw-r--r-- | modules/images.py | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/modules/images.py b/modules/images.py index b968d6a6..08a72e67 100644 --- a/modules/images.py +++ b/modules/images.py @@ -15,6 +15,7 @@ import piexif.helper from PIL import Image, ImageFont, ImageDraw, PngImagePlugin
from fonts.ttf import Roboto
import string
+import json
from modules import sd_samplers, shared, script_callbacks
from modules.shared import opts, cmd_opts
@@ -553,10 +554,45 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i return fullfn, txt_fullfn
+def read_info_from_image(image):
+ items = image.info or {}
+
+ geninfo = items.pop('parameters', None)
+
+ if "exif" in items:
+ exif = piexif.load(items["exif"])
+ exif_comment = (exif or {}).get("Exif", {}).get(piexif.ExifIFD.UserComment, b'')
+ try:
+ exif_comment = piexif.helper.UserComment.load(exif_comment)
+ except ValueError:
+ exif_comment = exif_comment.decode('utf8', errors="ignore")
+
+ items['exif comment'] = exif_comment
+ geninfo = exif_comment
+
+ for field in ['jfif', 'jfif_version', 'jfif_unit', 'jfif_density', 'dpi', 'exif',
+ 'loop', 'background', 'timestamp', 'duration']:
+ items.pop(field, None)
+
+ if items.get("Software", None) == "NovelAI":
+ try:
+ json_info = json.loads(items["Comment"])
+ sampler = sd_samplers.samplers_map.get(json_info["sampler"], "Euler a")
+
+ geninfo = f"""{items["Description"]}
+Negative prompt: {json_info["uc"]}
+Steps: {json_info["steps"]}, Sampler: {sampler}, CFG scale: {json_info["scale"]}, Seed: {json_info["seed"]}, Size: {image.width}x{image.height}, Clip skip: 2, ENSD: 31337"""
+ except Exception:
+ print(f"Error parsing NovelAI iamge generation parameters:", file=sys.stderr)
+ print(traceback.format_exc(), file=sys.stderr)
+
+ return geninfo, items
+
+
def image_data(data):
try:
image = Image.open(io.BytesIO(data))
- textinfo = image.text["parameters"]
+ textinfo, _ = read_info_from_image(image)
return textinfo, None
except Exception:
pass
|