Image scale to ratio (2lab)
Resize an image to a target size without wrecking its aspect ratio
- image
- image
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, soside_length1024 withupscale_by1.5 gets you a 1536-long-side result. Set it to1to 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 -lanczosfor clean upscaling,nearest-exactfor pixel-art fidelity,bicubicas the general middle ground. - crop -
disabledorcenter, defaultdisabled. If you need a strict target dimension rather than a proportional fit,centercrops 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.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| upscale_by | FLOAT | 1.00–100 | — |
| side_length | INT | 10241–18446744073709550000 | — |
| upscale_method | COMBO | nearest-exact | 6 options: nearest-exact, bilinear, bicubic, bislerp, area, lanczos |
| crop | COMBO | disabled | 2 options: disabled, center |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |