Aspect Ratio Resizer (nvmaxx)
The resize node that sets a limit, not a size
- images
- resized_images
- width
- height
Every workflow has that moment: you load a photo and it doesn't fit the box your model expects. You want 1024-wide input, your camera handed you a 6000×4000 landscape, and the stock resize node either squashes the proportions or makes you hand-calculate the other dimension and pray the math holds. Aspect Ratio Resizer is the "set a limit, not a size" fix for exactly that. You give it max dimensions, it computes the other side, and it never distorts anything.
What it actually does
It's one half of the tiny nvmax/aspect-ratio-resizer pack - the other half, Auto MegapixelReducer, targets a pixel budget instead of a width/height cap, same author, same install. This node resizes a batch of images with constraints you toggle independently. The inputs that matter:
- enable_width / max_width - cap the width (default 1024, range 64–8192, snaps in steps of 8).
- enable_height / max_height - the same for height.
- resize_mode -
downscale_only(default; leaves small images alone),upscale_only(only grows images that are under the caps), orboth(always force a fit - small images get blown up to the caps, so "both" really means "fit to these dimensions"). - interpolation -
bilinearby default, plus bicubic, area, nearest, lanczos and a couple of others.
You can constrain just one axis - width-only on a 1920×1080 shot at max 1024 gives you 1024×576, keeping 16:9.
How it works
The math is the boring kind that's easy to get wrong yourself. For each enabled constraint it computes a scale factor (max ÷ original), keeps the smallest one so the most restrictive side wins, then only resizes when your mode says it should. Output dimensions get rounded to even numbers, which keeps things happy downstream. Under the hood it's PyTorch's F.interpolate for everything except lanczos, which takes a detour through PIL.
It returns the resized images plus width and height as integers - wire those into an Empty Latent or sampler if you want the downstream resolution to exactly match what came out. The bundled frontend also logs an "Aspect Ratio Resizer Results" line (original → new, scale, which constraint fired) to the browser console, so you can confirm what actually happened.
Install
Nothing to download but the code - no models, no torch fork, no heavy dependencies. The pack's only declared dependency is Pillow, which ComfyUI already ships. In ComfyUI Manager, search "Aspect Ratio Resizer" (the pack lists as aspect-ratio-resizer). Or the manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/nvmax/aspect-ratio-resizer
Then restart ComfyUI. Both nodes land under image/resize when you right-click to add a node - look for the "(nvmaxx)" display name.
Where people get burned
- Node not showing up - you didn't restart. This pack registers on load; the fix is a restart, not a reinstall.
linearandtrilinearinterpolation error out mid-run. Genuine trap in the shipped code: those PyTorch modes expect 3D/5D tensors, and the node passes a 4D batch. Stick with bilinear, bicubic, area, nearest or lanczos.- "Nothing happened." Both constraints disabled is a passthrough by design. If you only care about width, flip height off and leave it.
upscale_onlysurprises - it fires whenever the image is under the caps, so a 512px thumbnail meets your 1024 cap and comes back doubled. That's the feature, not a bug; usedownscale_onlyif you want small images never touched.
One last note: this is a pixel-space resize, not a latent one, so it's the right tool for preprocessing inputs (Load Image → this → VAE encode), not for the hi-res-fix stage where you'd rather nudge the latent. It's a small, honest utility - and for "I have a pile of photos in arbitrary sizes and one downstream model," it's exactly the right one.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| max_width | INT | 102464–8192 | — |
| max_height | INT | 102464–8192 | — |
| enable_width | BOOLEAN | true | — |
| enable_height | BOOLEAN | true | — |
| resize_mode | COMBO | downscale_only | 3 options: downscale_only, upscale_only, both |
| interpolation | COMBO | bilinear | 7 options: nearest, linear, bilinear, bicubic, trilinear, area, +1 |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| resized_images | IMAGE | — |
| width | INT | — |
| height | INT | — |