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

LayerUtility: ImageScaleByAspectRatio

ImageScaleByAspectRatio — aspect-ratio resize, the original

By chflame163·Created 3 years ago·Updated 8 days ago· 3,118
LayerUtility: ImageScaleByAspectRatio
  • image
  • mask
  • image
  • mask
  • original_size
  • width
  • height
◄aspect_ratio▾►
â—„proportional_width2â–º
â—„proportional_height1â–º
◄fit▾►
◄method▾►
◄round_to_multiple▾►
â—„scale_to_longest_sidefalseâ–º
â—„longest_side1024â–º

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 like 1:1, 16:9, 2:3, 9:16. Choose custom to drive the ratio from proportional_width / proportional_height.
  • fit - letterbox pads the image to fit, crop fills the frame and trims the excess, fill stretches. 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, or None. 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.

Category😺dzNodes/LayerUtility

Inputs (10)

NameTypeDefaultDescription
aspect_ratioCOMBO9 options: original, custom, 1:1, 3:2, 4:3, 16:9, +3
proportional_widthINT21–999—
proportional_heightINT11–999—
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_longest_sideBOOLEANfalse—
longest_sideINT10244–999999—
imageoptIMAGE—
maskoptMASK—

Outputs (5)

NameTypeDescription
imageIMAGE—
maskMASK—
original_sizeBOX—
widthINT—
heightINT—