add resizing for multiples

This commit is contained in:
aria1th
2024-12-16 17:40:23 +09:00
parent 77e1429843
commit a384a92373
2 changed files with 34 additions and 2 deletions
+2 -2
View File
@@ -30,7 +30,7 @@ class SDWebuiAPINode:
"height": ("INT", {"default": 1024}),
"hr_scale": ("FLOAT", {"default": 1.5}),
"hr_upscale": ("STRING", {"default": "Latent"}),
"enable_hr": ("BOOL", {"default": False}),
"enable_hr": ("BOOLEAN", {"default": False}),
"cfg_scale": ("INT", {"default": 7}),
}
}
@@ -59,7 +59,7 @@ class SDWebuiAPIFallbackNode:
"height": ("INT", {"default": 1024}),
"hr_scale": ("FLOAT", {"default": 1.5}),
"hr_upscale": ("STRING", {"default": "Latent"}),
"enable_hr": ("BOOL", {"default": False}),
"enable_hr": ("BOOLEAN", {"default": False}),
"cfg_scale": ("INT", {"default": 7}),
}
}
+32
View File
@@ -442,6 +442,38 @@ class ResizeImageResolution:
"method": (["NEAREST", "LANCZOS", "BICUBIC"],),
},
}
@fundamental_node
class ResizeImageEnsuringMultiple:
FUNCTION = "resize_image_ensuring_multiple"
RETURN_TYPES = ("IMAGE",)
CATEGORY = "image"
custom_name = "Resize Image Ensuring W/H Multiple"
constants = {
"NEAREST": Image.Resampling.NEAREST,
"LANCZOS": Image.Resampling.LANCZOS,
"BICUBIC": Image.Resampling.BICUBIC,
}
@staticmethod
@PILHandlingHodes.output_wrapper
def resize_image_ensuring_multiple(image, multiple, method):
image = PILHandlingHodes.handle_input(image)
image_width, image_height = image.size
total_pixels = image_width * image_height
if total_pixels == 0:
raise RuntimeError("Image has no pixels")
target_width = (image_width // multiple) * multiple
target_height = (image_height // multiple) * multiple
return (image.resize((target_width, target_height), ResizeImageResolution.constants[method]),)
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"image": ("IMAGE",),
"multiple": ("INT", {"default": 32}),
"method": (["NEAREST", "LANCZOS", "BICUBIC"],),
},
}
@fundamental_node
class Base64DecodeNode: