aboutsummaryrefslogtreecommitdiff
path: root/modules/images.py
diff options
context:
space:
mode:
authorAUTOMATIC <16777216c@gmail.com>2022-09-23 17:37:47 +0300
committerAUTOMATIC <16777216c@gmail.com>2022-09-23 17:37:47 +0300
commit1a0353675de8b2f4d2ce784a37fe4d6121307131 (patch)
tree3ba85369a41c93ecb55c27accfa2163f38f06339 /modules/images.py
parent6fa20d51dcfd7db3286bc9dad31455b69b6daf65 (diff)
Option to use advanced upscalers with normal img2img
Diffstat (limited to 'modules/images.py')
-rw-r--r--modules/images.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/modules/images.py b/modules/images.py
index 6cf56ddb..c88ae475 100644
--- a/modules/images.py
+++ b/modules/images.py
@@ -209,8 +209,16 @@ def draw_prompt_matrix(im, width, height, all_prompts):
def resize_image(resize_mode, im, width, height):
+ def resize(im, w, h):
+ if opts.upscaler_for_img2img is None or opts.upscaler_for_img2img == "None":
+ return im.resize((w, h), resample=LANCZOS)
+
+ upscaler = [x for x in shared.sd_upscalers if x.name == opts.upscaler_for_img2img][0]
+ return upscaler.upscale(im, w, h)
+
if resize_mode == 0:
- res = im.resize((width, height), resample=LANCZOS)
+ res = resize(im, width, height)
+
elif resize_mode == 1:
ratio = width / height
src_ratio = im.width / im.height
@@ -218,9 +226,10 @@ def resize_image(resize_mode, im, width, height):
src_w = width if ratio > src_ratio else im.width * height // im.height
src_h = height if ratio <= src_ratio else im.height * width // im.width
- resized = im.resize((src_w, src_h), resample=LANCZOS)
+ resized = resize(im, src_w, src_h)
res = Image.new("RGB", (width, height))
res.paste(resized, box=(width // 2 - src_w // 2, height // 2 - src_h // 2))
+
else:
ratio = width / height
src_ratio = im.width / im.height
@@ -228,7 +237,7 @@ def resize_image(resize_mode, im, width, height):
src_w = width if ratio < src_ratio else im.width * height // im.height
src_h = height if ratio >= src_ratio else im.height * width // im.width
- resized = im.resize((src_w, src_h), resample=LANCZOS)
+ resized = resize(im, src_w, src_h)
res = Image.new("RGB", (width, height))
res.paste(resized, box=(width // 2 - src_w // 2, height // 2 - src_h // 2))