Nodes/ComfyUI-UniversalToolkit/Image Scale By Aspect Ratio (UTK)
ComfyUI Node

Image Scale By Aspect Ratio (UTK)

Scale an image to a target aspect ratio without mangling it

By whmc76·Created about a year ago·Updated 2 months ago· 72
Image Scale By Aspect Ratio (UTK)
  • image
  • mask
  • image
  • mask
  • original_size
  • width
  • height
  • batch_count
aspect_ratio
proportional_width1
proportional_height1
fit
method
round_to_multiple
scale_to_side
scale_to_length1024
background_colorblack
crop_positioncenter

Image Scale By Aspect Ratio (UTK) exists for one reason: "make this 16:9" is not the same as "stretch this to 16:9," and most people learn that the hard way when the subject turns into a pancake. This node resizes an image to a target aspect ratio while keeping the subject intact - and it's a KJNodes-style fit/scale tool, so it also handles the mask alongside the image and reports what it actually did.

How it works

You pick an aspect_ratio (original, custom, or a preset like 1:1, 3:2, 4:3, 16:9, 9:16 - with proportional_width / proportional_height for your own numbers), and then the fit mode decides what happens when the source doesn't match:

  • resize - scale to fit, no padding. Output is the scaled size, which may be smaller than the target on one axis.
  • pad - scale to fit and pad the leftover with a solid background_color (preset list: black, white, gray, plus colors). Output is exactly the target size.
  • stretch - force the target dimensions, distorting the aspect ratio. Almost never what you want.
  • pad_edge / pad_edge_pixel - pad with edge color reflected/stretched instead of a flat fill. Nice for video where a flat bar looks cheap.
  • crop - scale up until the target is covered, crop the overflow.
  • pillarbox_blur - pad with a blurred, darkened copy of the image. The cinematic look, and it's the one people end up on for video.

crop_position (center/top/bottom/left/right) controls where content sits inside the frame - top matters when you're framing a head-and-shoulders shot, for instance.

Then the plumbing: scale_to_side (longest/shortest/width/height/total pixel) and scale_to_length (default 1024) set the actual pixel size, round_to_multiple snaps it to 8/16/32/64 for AI-friendliness, and method picks the interpolation (lanczos/bicubic/hamming/bilinear/box/nearest).

Outputs

Five: image, mask (the same transformation applied to your mask input so they stay registered), original_size (a BOX of the input dimensions), width and height (the result), and batch_count.

Installing it

Standard pack install - ComfyUI Manager → search ComfyUI-UniversalToolkit, or clone into custom_nodes/:

cd ComfyUI/custom_nodes
git clone https://github.com/whmc76/ComfyUI-UniversalToolkit
cd ComfyUI-UniversalToolkit && pip install -r requirements.txt

Then restart. PIL-only, nothing heavy.

Gotchas

  • resize vs pad was a real bug here - earlier pack versions made them behave identically; v1.4.7 fixed it so resize returns the actual scaled size and pad fills to the target. If you're on an old version, update the pack before trusting these two.
  • pad modes fill the background with a color, not the image. If you want the blurred-copy look, use pillarbox_blur; a flat black bar reads as a black bar every time.
  • Mask input is optional but you usually want it - if you're scaling a face crop for inpainting, the mask needs to scale the same way or your inpaint region drifts off the face.

It's the kind of node you install once, forget, and reach for every time a workflow demands "land on exactly this aspect ratio." The pillarbox_blur mode alone makes it worth keeping around for video work.

CategoryUniversalToolkit/Image

Inputs (12)

NameTypeDefaultDescription
aspect_ratioCOMBO9 options: original, custom, 1:1, 3:2, 4:3, 16:9, +3
proportional_widthINT11–100000000
proportional_heightINT11–100000000
fitCOMBO7 options: stretch, resize, pad, pad_edge, pad_edge_pixel, crop, +1
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_colorCOMBOblack9 options: black, white, gray, red, green, blue, +3
crop_positionCOMBOcenter5 options: center, top, bottom, left, right
imageoptIMAGE
maskoptMASK

Outputs (6)

NameTypeDescription
imageIMAGE
maskMASK
original_sizeBOX
widthINT
heightINT
batch_countINT