diff --git a/external.py b/external.py index 21a9d08..f52d4e2 100644 --- a/external.py +++ b/external.py @@ -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}), } } diff --git a/io_node.py b/io_node.py index 0a22b9d..b46e660 100644 --- a/io_node.py +++ b/io_node.py @@ -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: