LayerUtility: ImageScaleByAspectRatio
ImageScaleByAspectRatio — aspect-ratio resize, the original
- image
- mask
- image
- mask
- original_size
- width
- height
This is the resize node you reach for when you need a specific aspect ratio and dimensions the sampler won't choke on. Pick a ratio, pick how the source fits into it, round the result to a clean multiple, done. It's the original version of the node - there's a V2 with a couple more controls - but for most resizing this one does the job without fuss.
How it works
You hand it an image (and optionally a mask, which is resized in lockstep so the two stay aligned), tell it the target ratio, and it scales and fits in a single pass. The design keeps three decisions separate: what shape you want, how you reconcile the source's shape with it, and what to round the final numbers to.
The inputs that matter
aspect_ratio-original,custom, or a preset like1:1,16:9,2:3,9:16. Choosecustomto drive the ratio fromproportional_width/proportional_height.fit-letterboxpads the image to fit,cropfills the frame and trims the excess,fillstretches. Crop for a full frame, letterbox when you can't lose any content.scale_to_longest_side+longest_side- flip the boolean on and set the length to pin the long edge to, say, 1024. This is how you set the output size without doing the math by hand. (This is the main thing V2 expands on, swapping this toggle for a more flexible per-side selector.)round_to_multiple- snaps the dimensions to a multiple of 8 through 512, orNone. Keep it at 8 or higher so the latent dimensions come out clean.
method is the resampler - lanczos is the sharp default.
Five outputs: image and mask (the resized pair), original_size (a BOX with the pre-resize dimensions, so you can scale back later), and width / height as ints for anything downstream that needs the numbers.
How to install it
ComfyUI Manager: search ComfyUI Layer Style, install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/chflame163/ComfyUI_LayerStyle
install requirements.txt, restart. It's under 😺dzNodes → LayerUtility.
Common issues
The usual gotcha is round_to_multiple left on None, which produces odd dimensions a downstream sampler may reject - round to 8 or 64 and it's fine. The other is fit: unexpected black bars mean you're in letterbox, a subtly stretched image means fill. If you want a letterbox fill color, per-side scaling, or a megapixel-budget target, step up to ImageScaleByAspectRatio V2 - but for straightforward "make it 16:9 at 1024 on the long edge, rounded to 64," this original is all you need.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| aspect_ratio | COMBO | 9 options: original, custom, 1:1, 3:2, 4:3, 16:9, +3 | |
| proportional_width | INT | 21–999 | — |
| proportional_height | INT | 11–999 | — |
| fit | COMBO | 3 options: letterbox, crop, fill | |
| method | COMBO | 6 options: lanczos, bicubic, hamming, bilinear, box, nearest | |
| round_to_multiple | COMBO | 8 options: 8, 16, 32, 64, 128, 256, +2 | |
| scale_to_longest_side | BOOLEAN | false | — |
| longest_side | INT | 10244–999999 | — |
| imageopt | IMAGE | — | |
| maskopt | MASK | — |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| original_size | BOX | — |
| width | INT | — |
| height | INT | — |