Nodes/comfyUI-tool-2lab/Image scale to ratio (2lab)
ComfyUI Node

Image scale to ratio (2lab)

Resize an image to a target size without wrecking its aspect ratio

By AI2lab·Created 2 years ago·Updated 2 years ago· 23
Image scale to ratio (2lab)
  • image
  • image
upscale_by1.0
side_length1024
upscale_methodnearest-exact
cropdisabled

Image_Scale_To_Ratio (2lab) is a resize node with the aspect-ratio problem already solved. Give it an image and a target side length, and it scales the image up or down while keeping its proportions intact - which is the part of image scaling that trips people up more than it should. Core ComfyUI's ImageScale needs you to supply width and height, and if you don't do the ratio math yourself you get a squashed image. This node does the math for you: one number in, proportional scaling out.

Where it earns its place: feeding images into a sampler that has a target resolution, or normalizing a batch of differently-sized images before they hit a shared pipeline (like the pack's batch nodes, which demand matching dimensions). Set side_length to 1024 and every image that passes through comes out scaled so its longest side is 1024, ratio intact.

How it works

Required inputs:

  • image - the input image tensor.
  • upscale_by - a float multiplier, default 1. A multiplier on top of the side-length target, so side_length 1024 with upscale_by 1.5 gets you a 1536-long-side result. Set it to 1 to scale exactly to the target.
  • side_length - the target length for the governing side, default 1024.
  • upscale_method - the interpolation method, and these six names should look familiar from core ComfyUI: nearest-exact, bilinear, bicubic, bislerp, area, lanczos. Same family of choices, same rules of thumb - lanczos for clean upscaling, nearest-exact for pixel-art fidelity, bicubic as the general middle ground.
  • crop - disabled or center, default disabled. If you need a strict target dimension rather than a proportional fit, center crops to it from the middle.

The image output is the resized tensor, ready to feed a VAE Encode, a sampler, or an upscale chain.

One detail worth knowing if you're scaling up for quality rather than just fitting: for real enlargement you'd normally pair this with a proper upscaler (think tiled upscaling or model-based upscalers) rather than relying on bicubic or lanczos interpolation alone - interpolation only gets you so far before it softens. Use this node to hit a target size; use a real upscale model when you actually want detail added.

Installing it

From AI2lab/comfyUI-tool-2lab. ComfyUI Manager → search comfyUI-tool-2lab → Install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/AI2lab/comfyUI-tool-2lab

Restart ComfyUI after. No models to download, no dependency fights - this pack is a Chinese dev's grab-bag of utilities (README one word long, every node labeled in 中文). If you've ever eyeballed a width for ImageScale and gotten a stretched face back, this is the node that stops you doing arithmetic by hand.

Category☁️2lab/image

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
upscale_byFLOAT1.00–100
side_lengthINT10241–18446744073709550000
upscale_methodCOMBOnearest-exact6 options: nearest-exact, bilinear, bicubic, bislerp, area, lanczos
cropCOMBOdisabled2 options: disabled, center

Outputs (1)

NameTypeDescription
imageIMAGE