mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-09-10 11:35:40 +00:00
ImageScaleToMaxDimension node. (#9689)
This commit is contained in:
@@ -625,6 +625,37 @@ class ImageFlip:
|
|||||||
|
|
||||||
return (image,)
|
return (image,)
|
||||||
|
|
||||||
|
class ImageScaleToMaxDimension:
|
||||||
|
upscale_methods = ["area", "lanczos", "bilinear", "nearest-exact", "bilinear", "bicubic"]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(s):
|
||||||
|
return {"required": {"image": ("IMAGE",),
|
||||||
|
"upscale_method": (s.upscale_methods,),
|
||||||
|
"largest_size": ("INT", {"default": 512, "min": 0, "max": MAX_RESOLUTION, "step": 1})}}
|
||||||
|
RETURN_TYPES = ("IMAGE",)
|
||||||
|
FUNCTION = "upscale"
|
||||||
|
|
||||||
|
CATEGORY = "image/upscaling"
|
||||||
|
|
||||||
|
def upscale(self, image, upscale_method, largest_size):
|
||||||
|
height = image.shape[1]
|
||||||
|
width = image.shape[2]
|
||||||
|
|
||||||
|
if height > width:
|
||||||
|
width = round((width / height) * largest_size)
|
||||||
|
height = largest_size
|
||||||
|
elif width > height:
|
||||||
|
height = round((height / width) * largest_size)
|
||||||
|
width = largest_size
|
||||||
|
else:
|
||||||
|
height = largest_size
|
||||||
|
width = largest_size
|
||||||
|
|
||||||
|
samples = image.movedim(-1, 1)
|
||||||
|
s = comfy.utils.common_upscale(samples, width, height, upscale_method, "disabled")
|
||||||
|
s = s.movedim(1, -1)
|
||||||
|
return (s,)
|
||||||
|
|
||||||
NODE_CLASS_MAPPINGS = {
|
NODE_CLASS_MAPPINGS = {
|
||||||
"ImageCrop": ImageCrop,
|
"ImageCrop": ImageCrop,
|
||||||
@@ -639,4 +670,5 @@ NODE_CLASS_MAPPINGS = {
|
|||||||
"GetImageSize": GetImageSize,
|
"GetImageSize": GetImageSize,
|
||||||
"ImageRotate": ImageRotate,
|
"ImageRotate": ImageRotate,
|
||||||
"ImageFlip": ImageFlip,
|
"ImageFlip": ImageFlip,
|
||||||
|
"ImageScaleToMaxDimension": ImageScaleToMaxDimension,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user