From a8d80e9fd96c5614d0aed898017ff24bbe5bf8f0 Mon Sep 17 00:00:00 2001 From: GiusTex <112352961+GiusTex@users.noreply.github.com> Date: Sun, 6 Oct 2024 13:45:04 +0200 Subject: [PATCH] fix new_width not found --- nodes.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/nodes.py b/nodes.py index b7f813b..30adf82 100644 --- a/nodes.py +++ b/nodes.py @@ -47,6 +47,13 @@ class PadImageForDiffusersOutpaint: source=im.convert('RGB') target_size = (width, height) + # Raise an error. + if source.width == width and source.height == height: + raise ValueError(f'Input image size is the same as target size, resize input image or change target size.') + + # Initialize new_width and new_height + new_width, new_height = source.width, source.height + # Upscale if source is smaller than target in both dimensions if source.width < target_size[0] and source.height < target_size[1]: scale_factor = min(target_size[0] / source.width, target_size[1] / source.height) @@ -60,12 +67,6 @@ class PadImageForDiffusersOutpaint: new_height = int(source.height * scale_factor) source = source.resize((new_width, new_height), Image.LANCZOS) - if source.width == target_size[0] and source.height != target_size[1]: - scale_factor = min(target_size[0] / source.width, target_size[1] / source.height) - new_width = target_size[0] - new_height = int(source.height * scale_factor) - source = source.resize((new_width, new_height), Image.LANCZOS) - if not can_expand(source.width, source.height, target_size[0], target_size[1], alignment): alignment = "Middle" # Calculate margins based on alignment