diff options
author | AUTOMATIC <16777216c@gmail.com> | 2022-09-30 07:38:48 +0000 |
---|---|---|
committer | AUTOMATIC <16777216c@gmail.com> | 2022-09-30 07:38:48 +0000 |
commit | a5e7b371d61bc063062b636236f1f37c264f4115 (patch) | |
tree | 297c2c3696ae8ebfa196e47f567eac7e6b7fae01 /modules/images.py | |
parent | 8f1b3153180da3b626529a7d077eac63d4b2e5e4 (diff) | |
download | stable-diffusion-webui-gfx803-a5e7b371d61bc063062b636236f1f37c264f4115.tar.gz stable-diffusion-webui-gfx803-a5e7b371d61bc063062b636236f1f37c264f4115.tar.bz2 stable-diffusion-webui-gfx803-a5e7b371d61bc063062b636236f1f37c264f4115.zip |
fix the bug with broken rescaling in PR
Diffstat (limited to 'modules/images.py')
-rw-r--r-- | modules/images.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/modules/images.py b/modules/images.py index a6538dbe..6430cfec 100644 --- a/modules/images.py +++ b/modules/images.py @@ -219,9 +219,17 @@ def resize_image(resize_mode, im, width, height): if opts.upscaler_for_img2img is None or opts.upscaler_for_img2img == "None" or im.mode == 'L':
return im.resize((w, h), resample=LANCZOS)
- upscaler = [x for x in shared.sd_upscalers if x.name == opts.upscaler_for_img2img][0]
- scale = w / im.width
- return upscaler.scaler.upscale(im, scale)
+ upscalers = [x for x in shared.sd_upscalers if x.name == opts.upscaler_for_img2img]
+ assert len(upscalers) > 0, f"could not find upscaler named {opts.upscaler_for_img2img}"
+
+ upscaler = upscalers[0]
+ scale = max(w / im.width, h / im.height)
+ upscaled = upscaler.scaler.upscale(im, scale)
+
+ if upscaled.width != w or upscaled.height != h:
+ upscaled = im.resize((w, h), resample=LANCZOS)
+
+ return upscaled
if resize_mode == 0:
res = resize(im, width, height)
|