Kaola Image Scale By Aspect Ratio
Crop, letterbox, or stretch to any ratio
- image
- image
- mask
- original_size
- target_size
Diffusion models are picky about canvas shape. Feed a 1.78:1 image to an SDXL or Flux model trained on 1:1 and you're either wasting latent budget on a stretched composition or fighting letterbox bars you never asked for. KaolaImageScaleByAspectRatio is the "make it the right shape" step, and it does it without making you hand-calculate what 16:9 at a 1024 longest edge even comes out to.
It's the most featureful of the three nodes in the Kaola pack. It takes any image, decides a target aspect ratio and size, conforms it one of three ways - crop to fit, letterbox with bars, or stretch - and rounds the result to a multiple you choose. That last part matters more than it looks: latent diffusion is built around multiples of 8 (and often 64), so a clean 1024×576 instead of a weird 1023×574 is the difference between a smooth decode and artifacts on a batch.
The inputs that actually matter
There are nine, but you'll set three of them most of the time:
- aspect_ratio - presets for the common shapes (1:1, 16:9, 4:3, 3:2, 2:3, 9:16, 3:4, 21:9, 9:21) plus
originalandcustom. For custom, setaspect_ratio_width/aspect_ratio_heightas floats. - scale_mode + target_length - this pair is where people mix things up.
scale_modedecides which edgetarget_lengthpins:by_width,by_height,by_longest, orby_shortest.by_longest(the default) with 1024 means a landscape comes out 1024 wide and a portrait comes out 1024 tall. - fit_mode -
letterbox(default),crop, orstretch. Stretch is usually the wrong answer for diffusion - it distorts geometry and faces.cropkeeps the composition centered but throws away content.letterboxkeeps everything and pads withbackground_color, which is the go-to for feeding a model a non-native aspect without distortion.
Rounding is multiple_of (default 8), and the resample algorithm is method - lanczos by default, which is the right default for both up and down.
The outputs
image, plus a mask and two size strings. The mask is the quiet win: in letterbox mode it's 1.0 over the real content and 0.0 in the bars, so you can composite the result back over other content later, or route it to a detailer/inpaint pass that should only touch the picture area. In crop and stretch modes the mask is just full white - don't go looking for a coverage mask there. original_size and target_size come out as plain "WxH" strings, handy for debugging and for display nodes.
How it works
Deterministic PIL math - no model, no VRAM, runs in milliseconds. It computes the target dimensions from the aspect ratio and scale mode, rounds down to multiple_of, then resizes each frame per the chosen method. It's the "reach for a millisecond, deterministic operation instead of burning a diffusion pass" category - it will never invent detail, and you wouldn't want it to.
Gotchas
multiple_ofrounds down. Ask forby_width1000 withmultiple_of8 and you get 992, not 1000. That's the feature working as intended, but it surprises people the first time.- The size strings describe the canvas, not the content. In letterbox mode,
target_sizeis the full padded box, not the visible image. - Overlap with core ComfyUI. For plain resizing this duplicates
ImageScaleandImageScaleToTotalPixels. Where it earns its place is the one-node combo - aspect ratio, fit mode, multiple-of rounding, and a mask - for prepping inputs to a generation pass.
Installation
Same as the rest of the pack, and it's light:
cd ComfyUI/custom_nodes/
git clone https://github.com/kana112233/ComfyUI-Kaola-Nodes.git
Restart after cloning, or use ComfyUI Manager (search "ComfyUI-Kaola-Nodes"). No models to download, no requirements.txt, no dependency drama - this is the rare custom-node install that just works.
For most people the combinations that actually get used are 16:9 or 9:16 + by_longest 1024 + crop for reframing, or letterbox for handing SDXL/Flux a non-native shape without distortion. Small pack, but this is the node you'd keep.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | 输入图像 | Input image | |
| aspect_ratio | COMBO | original | 目标宽高比 | Target aspect ratio |
| aspect_ratio_width | FLOAT | 16.01–10000 | 自定义宽高比宽度 (当选择custom时生效) | Custom aspect ratio width |
| aspect_ratio_height | FLOAT | 9.01–10000 | 自定义宽高比高度 (当选择custom时生效) | Custom aspect ratio height |
| scale_mode | COMBO | by_longest | 缩放基准模式 | Scale mode based on dimension |
| target_length | INT | 102464–8192 | 目标边长 | Target length for the chosen scale mode |
| fit_mode | COMBO | letterbox | 适配模式: Letterbox(黑边), Crop(裁剪), Stretch(拉伸) | Fit mode |
| background_color | STRING | #000000 | Letterbox模式下的背景颜色(十六进制) | Background color for letterbox mode (hex) |
| multiple_of | INT | 81–512 | 输出尺寸圆整倍数 (通常为8) | Round output dimensions to multiple of (usually 8) |
| method | COMBO | lanczos | 缩放算法 | Resampling method |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| original_size | STRING | — |
| target_size | STRING | — |