Nodes/ComfyUI Layer Style/LayerUtility: ImageScaleByAspectRatio V2
ComfyUI Node Runs on cloud

LayerUtility: ImageScaleByAspectRatio V2

ImageScaleByAspectRatio V2 — resize to any ratio, snapped to sampler-friendly dimensions

By chflame163·Created 3 years ago·Updated 5 days ago· 3,113
LayerUtility: ImageScaleByAspectRatio V2
  • image
  • mask
  • image
  • mask
  • original_size
  • width
  • height
◄aspect_ratio▾►
â—„proportional_width1â–º
â—„proportional_height1â–º
◄fit▾►
◄method▾►
◄round_to_multiple▾►
◄scale_to_side▾►
â—„scale_to_length1024â–º
â—„background_color#000000â–º

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 like 1:1, 16:9, 2:3. Pick custom and it uses proportional_width / proportional_height as the ratio.
  • fit - the important one. letterbox pads to fit (with background_color filling the bars), crop fills the frame and trims the overflow, fill stretches 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 the longest or shortest side, or width/height, or total_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, or None. 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.

Category😺dzNodes/LayerUtility

Inputs (11)

NameTypeDefaultDescription
aspect_ratioCOMBO9 options: original, custom, 1:1, 3:2, 4:3, 16:9, +3
proportional_widthINT11–100000000—
proportional_heightINT11–100000000—
fitCOMBO3 options: letterbox, crop, fill
methodCOMBO6 options: lanczos, bicubic, hamming, bilinear, box, nearest
round_to_multipleCOMBO8 options: 8, 16, 32, 64, 128, 256, +2
scale_to_sideCOMBO6 options: None, longest, shortest, width, height, total_pixel(kilo pixel)
scale_to_lengthINT10244–100000000—
background_colorSTRING#000000—
imageoptIMAGE—
maskoptMASK—

Outputs (5)

NameTypeDescription
imageIMAGE—
maskMASK—
original_sizeBOX—
widthINT—
heightINT—