fix new_width not found

This commit is contained in:
GiusTex
2024-10-06 13:45:04 +02:00
committed by GitHub
parent 43bf24a891
commit a8d80e9fd9
+7 -6
View File
@@ -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