LayerUtility: ImageScaleByAspectRatio V2
ImageScaleByAspectRatio V2 — resize to any ratio, snapped to sampler-friendly dimensions
- image
- mask
- image
- mask
- original_size
- width
- height
Resizing sounds like a solved problem until you're doing it inside a diffusion workflow, where the target has to be a specific aspect ratio and divisible by 8 or 64 or the sampler complains. This node handles all of that in one box: pick a ratio, pick how to fit into it, pick what to round the dimensions to, and it hands you a clean image plus the numbers you'll need later. It's one of the quiet workhorses of the Layer Style pack - not exciting, used constantly.
How it works
You give it an image (and optionally a mask, which gets resized identically so they stay in register), tell it the shape you want, and it does the scale-and-fit in one pass. The interesting part is that it separates three decisions people usually conflate: what ratio, how big, and how to reconcile the source's shape with the target's.
The inputs that actually matter
aspect_ratio-original,custom, or a preset like1:1,16:9,2:3. Pickcustomand it usesproportional_width/proportional_heightas the ratio.fit- the important one.letterboxpads to fit (withbackground_colorfilling the bars),cropfills the frame and trims the overflow,fillstretches to fit. Crop for a clean fill, letterbox when you can't afford to lose any of the image.scale_to_side+scale_to_length- how big the result is. Pin thelongestorshortestside, orwidth/height, ortotal_pixel(kilo pixel)to target a megapixel budget, then set the length. This is how you say "make the long edge 1024" without doing arithmetic.round_to_multiple- snaps the final dimensions to a multiple of 8, 16, 32… up to 512, orNone. Keep it at 8 or higher so the latent dimensions come out clean and the KSampler doesn't choke.
method is the resampler (lanczos is the sharp default; leave it unless you have a reason).
Five outputs: image and mask (the resized pair), original_size (a BOX carrying the pre-resize dimensions - save it if you plan to scale back afterward), and width / height ints you can route into other nodes that need the numbers.
How to install it
In ComfyUI Manager, search ComfyUI Layer Style, install, restart. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/chflame163/ComfyUI_LayerStyle
install requirements.txt into ComfyUI's Python, and restart. The node lives under 😺dzNodes → LayerUtility.
Common issues
The classic mistake is leaving round_to_multiple on None and then wondering why a downstream sampler errors on odd dimensions - round to 8 or 64 and it goes away. The other one is fit: people set letterbox and get unexpected black bars, or set fill and get a subtly stretched image. If the framing looks wrong, that dropdown is almost always the cause. And if you don't need per-side scaling or a letterbox color, the original ImageScaleByAspectRatio (no V2) is the simpler node - V2 mainly adds the scale_to_side control and the background fill.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| aspect_ratio | COMBO | 9 options: original, custom, 1:1, 3:2, 4:3, 16:9, +3 | |
| proportional_width | INT | 11–100000000 | — |
| proportional_height | INT | 11–100000000 | — |
| 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_side | COMBO | 6 options: None, longest, shortest, width, height, total_pixel(kilo pixel) | |
| scale_to_length | INT | 10244–100000000 | — |
| background_color | STRING | #000000 | — |
| imageopt | IMAGE | — | |
| maskopt | MASK | — |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| original_size | BOX | — |
| width | INT | — |
| height | INT | — |