Scale By Long Side @zn123
The 'fit inside a box' node for mixed-size inputs
- image
- scaled_image
- width
- height
If you've ever dragged a 4K photo into a pipeline built for 1024-ish inputs and watched it grind, you know the pain Scale By Long Side @zn123 exists to remove. It rescales an image so its longest edge lands exactly on a target you choose, aspect ratio preserved. Think of it as "fit inside a box of this size" - the one knob for people who want to cap the biggest dimension rather than force a specific shape.
The situation it's for
Your inputs don't agree with each other. One reference is 2048x2048, the next is 4000x3000, the next is a phone portrait at 1170x2532. Feeding that mess straight into a batch pipeline means one image blows up VRAM while the next is too small to matter. Long-side scaling normalizes the ceiling: everything comes out with its largest edge at, say, 1024, and the smaller edge falls wherever the aspect ratio says. Landscape, portrait, square - all fit the same box.
That's the flip side of the pack's Scale By Short Side node. Short side enforces a floor (nobody is under 1024); this enforces a ceiling (nobody is over 1024). Different jobs, both useful.
How it works
The math is the mirror image of the short-side node. It reads the current long side, computes scale_factor = long_side_target / current_long_side, and scales both dimensions by it (rounded), before handing off to ComfyUI's common_upscale with your chosen method.
The inputs that matter:
long_side_target- INT, 64 to 8192, default 1024. The length your long edge will become.upscale_method-nearest,bilinear,bicubic,area,lanczos(defaultbicubic).only_upscale- BOOLEAN, default true.
Outputs are scaled_image (IMAGE) plus width and height (INT) - the same pair as its sibling, and just as handy for wiring real dimensions into an Empty Latent Image or a dimension-dependent node so your conditioning always matches reality.
The gotcha: default behavior is 'skip if already small enough'
only_upscale defaults to true. If your image's long side is already at or under the target, the node returns it untouched - original image, original width/height. Perfect for "never let anything exceed 1024" as a safety cap, because small images pass straight through without resampling. But it is not a "resize everything to fit 1024" tool until you set only_upscale to false. Feed it a 3000px image expecting it to shrink to 1024 and - default settings - nothing happens. That single toggle is where most people think the node is broken when it's actually being polite.
Installing it
It's part of the ComfyUI-image-processor-zn123 pack:
- ComfyUI Manager - search "ComfyUI-image-processor-zn123", install, restart.
- Manual - from
ComfyUI/custom_nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/zn123/ComfyUI-image-processor-zn123
Restart, find it under image/processor. No models, no downloads, no heavy deps - just torch/numpy/Pillow, all already in ComfyUI.
Gotchas
- only_upscale=true is the default, and it means "don't downscale." Turn it off if you actually want big images pulled down to the cap.
- It's interpolation, not restoration. Capping a big image down is lossy - if you then want it up later, upscale from the original, not from the capped version.
areais the better method when you're shrinking (onceonly_upscaleis off); stick withbicubic/lanczoswhen your target is bigger than the source.
Ceiling, box, done. If your pipeline keeps choking on oversized inputs, this is the quiet node that fixes it.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| long_side_target | INT | 102464–8192 | — |
| upscale_method | COMBO | bicubic | 5 options: nearest, bilinear, bicubic, area, lanczos |
| only_upscale | BOOLEAN | true | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| scaled_image | IMAGE | — |
| width | INT | — |
| height | INT | — |