@@ -625,6 +625,37 @@ def flip(self, image, flip_method):
625625
626626 return (image ,)
627627
628+ class ImageScaleToMaxDimension :
629+ upscale_methods = ["area" , "lanczos" , "bilinear" , "nearest-exact" , "bilinear" , "bicubic" ]
630+
631+ @classmethod
632+ def INPUT_TYPES (s ):
633+ return {"required" : {"image" : ("IMAGE" ,),
634+ "upscale_method" : (s .upscale_methods ,),
635+ "largest_size" : ("INT" , {"default" : 512 , "min" : 0 , "max" : MAX_RESOLUTION , "step" : 1 })}}
636+ RETURN_TYPES = ("IMAGE" ,)
637+ FUNCTION = "upscale"
638+
639+ CATEGORY = "image/upscaling"
640+
641+ def upscale (self , image , upscale_method , largest_size ):
642+ height = image .shape [1 ]
643+ width = image .shape [2 ]
644+
645+ if height > width :
646+ width = round ((width / height ) * largest_size )
647+ height = largest_size
648+ elif width > height :
649+ height = round ((height / width ) * largest_size )
650+ width = largest_size
651+ else :
652+ height = largest_size
653+ width = largest_size
654+
655+ samples = image .movedim (- 1 , 1 )
656+ s = comfy .utils .common_upscale (samples , width , height , upscale_method , "disabled" )
657+ s = s .movedim (1 , - 1 )
658+ return (s ,)
628659
629660NODE_CLASS_MAPPINGS = {
630661 "ImageCrop" : ImageCrop ,
@@ -639,4 +670,5 @@ def flip(self, image, flip_method):
639670 "GetImageSize" : GetImageSize ,
640671 "ImageRotate" : ImageRotate ,
641672 "ImageFlip" : ImageFlip ,
673+ "ImageScaleToMaxDimension" : ImageScaleToMaxDimension ,
642674}
0 commit comments