fix the bug with broken rescaling in PR
This commit is contained in:
parent
8f1b315318
commit
a5e7b371d6
2 changed files with 12 additions and 4 deletions
|
@ -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':
|
if opts.upscaler_for_img2img is None or opts.upscaler_for_img2img == "None" or im.mode == 'L':
|
||||||
return im.resize((w, h), resample=LANCZOS)
|
return im.resize((w, h), resample=LANCZOS)
|
||||||
|
|
||||||
upscaler = [x for x in shared.sd_upscalers if x.name == opts.upscaler_for_img2img][0]
|
upscalers = [x for x in shared.sd_upscalers if x.name == opts.upscaler_for_img2img]
|
||||||
scale = w / im.width
|
assert len(upscalers) > 0, f"could not find upscaler named {opts.upscaler_for_img2img}"
|
||||||
return upscaler.scaler.upscale(im, scale)
|
|
||||||
|
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:
|
if resize_mode == 0:
|
||||||
res = resize(im, width, height)
|
res = resize(im, width, height)
|
||||||
|
|
|
@ -60,7 +60,7 @@ class Upscaler:
|
||||||
break
|
break
|
||||||
img = self.do_upscale(img, selected_model)
|
img = self.do_upscale(img, selected_model)
|
||||||
if img.width != dest_w or img.height != dest_h:
|
if img.width != dest_w or img.height != dest_h:
|
||||||
img = img.resize((dest_w, dest_h), resample=LANCZOS)
|
img = img.resize((int(dest_w), int(dest_h)), resample=LANCZOS)
|
||||||
|
|
||||||
return img
|
return img
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue