mirror of
https://github.com/justUmen/Bjornulf_custom_nodes.git
synced 2026-03-25 14:25:44 -03:00
...
This commit is contained in:
@@ -23,6 +23,30 @@ class ResizeImage:
|
||||
# Ensure the input image is on CPU and convert to numpy array
|
||||
image_np = image.cpu().numpy()
|
||||
|
||||
# Get original dimensions
|
||||
if image_np.ndim == 4:
|
||||
orig_height, orig_width = image_np.shape[1:3]
|
||||
else:
|
||||
orig_height, orig_width = image_np.shape[:2]
|
||||
|
||||
# Calculate new dimensions maintaining aspect ratio if needed
|
||||
aspect_ratio = orig_width / orig_height
|
||||
|
||||
if width == 0 and height == 0:
|
||||
# If both are 0, use original dimensions
|
||||
new_width, new_height = orig_width, orig_height
|
||||
elif width == 0:
|
||||
# If width is 0, calculate it based on height
|
||||
new_height = height
|
||||
new_width = int(height * aspect_ratio)
|
||||
elif height == 0:
|
||||
# If height is 0, calculate it based on width
|
||||
new_width = width
|
||||
new_height = int(width / aspect_ratio)
|
||||
else:
|
||||
# Use provided dimensions
|
||||
new_width, new_height = width, height
|
||||
|
||||
# Check if the image is in the format [batch, height, width, channel]
|
||||
if image_np.ndim == 4:
|
||||
# If so, we'll process each image in the batch
|
||||
@@ -31,7 +55,7 @@ class ResizeImage:
|
||||
# Convert to PIL Image
|
||||
pil_img = Image.fromarray((img * 255).astype(np.uint8))
|
||||
# Resize
|
||||
resized_pil = pil_img.resize((width, height), Image.LANCZOS)
|
||||
resized_pil = pil_img.resize((new_width, new_height), Image.LANCZOS)
|
||||
# Convert back to numpy and normalize
|
||||
resized_np = np.array(resized_pil).astype(np.float32) / 255.0
|
||||
resized_images.append(resized_np)
|
||||
@@ -45,7 +69,7 @@ class ResizeImage:
|
||||
# Convert to PIL Image
|
||||
pil_img = Image.fromarray((image_np * 255).astype(np.uint8))
|
||||
# Resize
|
||||
resized_pil = pil_img.resize((width, height), Image.LANCZOS)
|
||||
resized_pil = pil_img.resize((new_width, new_height), Image.LANCZOS)
|
||||
# Convert back to numpy and normalize
|
||||
resized_np = np.array(resized_pil).astype(np.float32) / 255.0
|
||||
# Add batch dimension if it was originally present
|
||||
@@ -56,7 +80,7 @@ class ResizeImage:
|
||||
|
||||
# Update metadata if needed
|
||||
if extra_pnginfo is not None:
|
||||
extra_pnginfo["resized_width"] = width
|
||||
extra_pnginfo["resized_height"] = height
|
||||
extra_pnginfo["resized_width"] = new_width
|
||||
extra_pnginfo["resized_height"] = new_height
|
||||
|
||||
return (resized_tensor, prompt, extra_pnginfo)
|
||||
Reference in New Issue
Block a user