From 1a0353675de8b2f4d2ce784a37fe4d6121307131 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Fri, 23 Sep 2022 17:37:47 +0300 Subject: Option to use advanced upscalers with normal img2img --- modules/images.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'modules/images.py') 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)) -- cgit v1.2.1