Update image_nodes.py

This commit is contained in:
kijai 2024-05-29 22:37:34 +03:00
parent a15d79d5dc
commit 2c7e8613e0

View File

@ -1315,9 +1315,18 @@ highest dimension.
_, width, height, _ = get_image_size.shape _, width, height, _ = get_image_size.shape
if keep_proportion: if keep_proportion:
ratio = min(width / W, height / H) # If one of the dimensions is zero, calculate it to maintain the aspect ratio
width = round(W * ratio) if width == 0 and height != 0:
height = round(H * ratio) ratio = height / H
width = round(W * ratio)
elif height == 0 and width != 0:
ratio = width / W
height = round(H * ratio)
elif width != 0 and height != 0:
# Scale based on which dimension is smaller in proportion to the desired dimensions
ratio = min(width / W, height / H)
width = round(W * ratio)
height = round(H * ratio)
else: else:
if width == 0: if width == 0:
width = W width = W