Rescale Image To Side
Resize by longest or shortest edge, aspect ratio untouched
- Image
- image
ComfyUI's stock image-scale nodes want you to specify exact width and height, which is fine until you don't actually care about exact dimensions - you just want "make the longest side 1024" or "shrink until the short edge hits 512" without doing the ratio math in your head every time. That's what this node is for. It's a small utility, but it's the kind of small utility you end up using constantly once it's in your graph, because "match this side length" is a far more common real need than "hit these exact pixels."
How it works
You give it an image and either a longest-side target, a shortest-side target, or both. It figures out the scale factor that hits your target on the specified edge and applies it uniformly, so the aspect ratio never distorts - no stretching, no squashing. Under the hood it picks its resampling method based on direction: Lanczos for upscaling (sharper edge reconstruction when you're adding pixels) and area interpolation for downscaling (better at avoiding moiré and aliasing when you're throwing pixels away). That's a sensible default pairing - Lanczos and area are the standard "right tool for the direction" choice, not an arbitrary pick.
This matters more than it sounds like. Most architectures have a native pixel budget they were trained at - SDXL wants around 1024×1024-equivalent, SD 1.5 wants 512×512, and going meaningfully off that budget is what produces the double-heads and repeated-limb artifacts people complain about. Getting your source image into the right ballpark before you feed it into img2img, a ControlNet preprocessor, or an upscale pipeline is exactly the kind of prep step this node exists for.
The inputs and outputs that matter
Image- the input, required, with a tooltip straight from the author: "the input image to be rescaled."Longest Side(optional, 0–8192, default 0) - target size for the longest edge. Leave at 0 to ignore it.Shortest Side(optional, 0–8192, default 0) - target size for the shortest edge. Leave at 0 to ignore it.
Both are optional and both default to "ignore," so you'll set exactly one of them in practice: longest-side when you want to cap how big an image can get (before an expensive ControlNet pass, say), shortest-side when you want to guarantee a minimum resolution regardless of orientation. Output is a single image, same aspect ratio as the input, resized to hit your target.
How to install it
Search KGnodes in ComfyUI Manager, or clone it manually:
cd ComfyUI/custom_nodes
git clone https://github.com/shahkoorosh/ComfyUI-KGnodes.git
pip install -r requirements.txt
Restart ComfyUI, find it under Add Node → 🎨KG as "Scale To Side." No models involved - this is pure interpolation, so it's essentially free on your GPU budget.
Common issues & troubleshooting
Nothing seems to happen. Both Longest Side and Shortest Side default to 0, which the node treats as "ignore this input." If you leave both at 0, you'll get your image back unchanged (or close to it) - set at least one of them to a real target.
Setting both at once gives a result you didn't expect. The two targets are answering different questions (cap the max edge vs. guarantee a min edge), and they're not designed to be reconciled together on the same image unless the math happens to agree. If you only care about one constraint, leave the other at 0 rather than setting both and hoping.
Upscaled result looks softer than you wanted. Lanczos is a solid general-purpose upscaler, but it's still just interpolation - it's not adding detail that wasn't there. If you're pushing an image up a lot (say, doubling it), this node gets you to the right canvas size, but a proper upscale model afterward is still the move if quality matters, not size alone.
Downscaled image looks slightly different from a naive resize. That's the area interpolation doing its job - it's deliberately not the sharpest option because sharp downscaling tends to alias on fine detail (hair, fabric texture, text). If you specifically want a crisper downscale and don't mind a bit of aliasing, that's a tradeoff this node has already made for you, not a bug.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| Image | IMAGE | The input image to be rescaled. | |
| Longest Sideopt | INT | 00–8192 | Target size for the longest side. 0 to ignore. |
| Shortest Sideopt | INT | 00–8192 | Target size for the shortest side. 0 to ignore. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |