Image Scale By Side - automatically determine which side to use
TeaCrab opened this issue · comments
Forgot how to do a pull request.
This allows the Image Scale by Side node to automatically use whichever side is longer for image resizing.
`
class ImageScale_Side:
upscale_methods = ["nearest-exact", "bilinear", "area"]
crop_methods = ["disabled", "center"]
def __init__(self) -> None:
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"image": ("IMAGE",),
"max_width": field.INT,
"max_height": field.INT,
"upscale_method": (cls.upscale_methods,),
"crop": (cls.crop_methods,)}}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "upscale"
CATEGORY = TREE_IMAGES
def upscale(self, image, upscale_method, max_width, max_height, crop):
samples = image.movedim(-1, 1)
size = get_image_size(image)
width_B = int(size[0])
height_B = int(size[1])
width = width_B
height = height_B
if width >= height:
heigh_ratio = height_B / width_B
width = max_width
height = heigh_ratio * width
else:
width_ratio = width_B / height_B
height = max_height
width = width_ratio * height
width = math.ceil(width)
height = math.ceil(height)
cls = comfy.utils.common_upscale(samples, width, height, upscale_method, crop)
cls = cls.movedim(1, -1)
return (cls,)`
Added as default choice for side scale nodes.