Nodes/ComfyUI/Scale Image to Max Dimension
ComfyUI Node Runs on cloud

Scale Image to Max Dimension

The fit-in-a-box resize

By Comfy-Org·Created 4 years ago·Updated 31 minutes ago· 129,926
Scale Image to Max Dimension
  • image
  • IMAGE
upscale_method
largest_size512

Some workflows don't want a specific size, they want a ceiling. Scale Image to Max Dimension takes your image and resizes it so the longest edge lands exactly on a number you pick - 1024, say - and the other edge scales along for the ride, aspect ratio intact. It's the "make sure everything fits my canvas" node, and it's the newest of the four in this family, having landed in ComfyUI core in September 2025.

The family it belongs to

This node sits in image/upscaling with ImageScale, ImageScaleBy and ImageScaleToTotalPixels, and it shares their character completely: it's a pixel resampler, not a detail factory. In the three-way split that dominates upscaling discussion - more pixels, more detail, more pixels over time - everything in this category only ever does the first. That's fine, and often exactly right: it runs in milliseconds, can't invent content, can't wreck a face. You reach for it when the source already has the detail and you just need it to be a certain size.

How it works

The logic is a single if/else. If the height is the longer edge, height becomes largest_size and width scales proportionally. If the width is longer, the reverse. Square images just get both edges set to largest_size. No cropping ever happens - the crop is hardcoded disabled in the source, so the whole image always survives.

if height > width:
    new_w = round((width / height) * largest_size)
    new_h = largest_size
elif width > height:
    new_h = round((height / width) * largest_size)
    new_w = largest_size

One thing people misread: "max dimension" doesn't mean "only shrink if too big." It means "resize so the longest edge equals this." Feed it a 512px image with largest_size at 1024 and it will happily upscale to 1024. The default is 512, which will enlarge most modern sources, so set it deliberately.

The inputs

  • largest_size - the length of the longest edge after resizing, 0 to 16384, default 512. The whole node in one number.
  • upscale_method - lanczos for upscaling, area when you're pulling images down to fit.
  • image - in, and out as the same IMAGE type.

One IMAGE output, and it behaves like every other IMAGE in ComfyUI: wire it to a VAE encode, a ControlNet, a sampler, or a save node.

When you'd reach for it

Its natural home is batch and reference work. Feeding a folder of wildly different images - some 2048 tall, some 384 wide - into an image-edit model, a ControlNet, or an IPAdapter? Run them all through this node at, say, 1024 or 1344, and every input lands inside the model's comfortable range. It's also the polite way to hand a source to a generative upscaler with a maximum input size without doing the aspect-ratio math yourself. Given how new it is, you'll mostly meet it in recent workflows and template packs.

Where people get burned

Same trap as the rest of the family: interpolation adds no detail, so upscaling a small source to 2048 just gives you a big soft image. If you want better, that's ImageUpscaleWithModel with an ESRGAN checkpoint or a generative model - this node is only about fitting a box. The other gotcha is the default. largest_size at 512 will quietly downscale your 1024-wide reference, and people notice the quality loss long before they notice the node.

Categoryimage/upscaling

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
upscale_methodCOMBO6 options: area, lanczos, bilinear, nearest-exact, bilinear, bicubic
largest_sizeINT5120–16384

Outputs (1)

NameTypeDescription
IMAGEIMAGE