Auto Megapixel Reducer (nvmaxx)
The Auto Megapixel Reducer
- images
- resized_images
- width
- height
Image-editing models that take a reference image have a resolution ceiling, and it's lower than you'd like. Flux 1 Kontext - the multimodal edit model from mid-2025 - is the canonical case: feed it a photo over roughly 2.1 megapixels and it gets unpredictable, and it can OOM outright. The author of this pack built Auto MegapixelReducer specifically for that, so when you load a 8K photo it silently shrinks it to whatever pixel budget you set, keeping the aspect ratio intact, before the model ever sees it.
What it does
It ships in the same nvmax/aspect-ratio-resizer pack as AspectRatioResizer (one install gets you both). The difference is the unit: instead of a width and height cap you set a single number, and the node figures out the dimensions. The inputs that matter:
- max_megapixels - the budget (default 2.1, range 0.1–50). The default isn't arbitrary: 2.1MP is the practical Kontext ceiling.
- only_reduce - "safe mode", on by default: never grow a small image.
- interpolation -
bilineardefault, same menu as its sibling (bicubic, area, nearest, lanczos…).
So 3840×2160 (8.3MP) with a 2.0 budget comes back at 1884×1060 - 2.0MP, still 16:9.
How it works
It computes the current megapixels (width × height / 1,000,000), and if you're already under budget it passes the image through untouched. Otherwise it takes the square root of budget ÷ current as a scale factor, applies it to both dimensions, rounds to even numbers, and resizes via PyTorch's F.interpolate (lanczos goes through PIL). Because both sides scale by the same factor, the aspect ratio is mathematically preserved. It also returns width and height as integers, handy if a downstream sampler needs to match.
The gotcha nobody mentions
only_reduce is currently decorative. In the shipped v1.1.9 code the node never upscales no matter what the toggle says - the "allow upscaling" branch the README describes isn't actually in the code. Small images always come out untouched, which is the safe behavior anyway. Leave the default on and forget it exists.
Install
Same pack, so if you already have AspectRatioResizer you're done. Otherwise, ComfyUI Manager → search "Aspect Ratio Resizer", or:
cd ComfyUI/custom_nodes
git clone https://github.com/nvmax/aspect-ratio-resizer
Restart, and it appears under image/resize as "Auto Megapixel Reducer (nvmaxx)". No models, no extra dependencies beyond Pillow (already bundled with ComfyUI).
The workflow it was built for
The author's own pattern, straight from when Flux 1 Kontext shipped: load your huge holiday photo → this node drops it to ~2.1MP keeping the ratio → Kontext does the edit → an SD upscaler takes the result back to full resolution. Downscale, edit, upscale back. The same trick applies to Qwen-Image-Edit, which shares that input-size sensitivity, and to any vision-LLM node that has to VAE-encode a reference image on limited VRAM. Roughly: if the step before it OOMs or misbehaves on big inputs, this is a one-node fix.
Troubleshooting
linear/trilinearinterpolation throw an error. Same trap as the sibling node - those PyTorch modes need 3D/5D tensors and get a 4D batch. Use bilinear, bicubic, area, nearest or lanczos.- Output is a hair over or under your target MP. Even-number rounding means it lands near the budget, not exactly on it. Not a bug.
- The console feedback - the bundled frontend logs original → new, megapixel change and target to the browser console, so you can see what it decided without trusting the output.
It's a one-trick node, but it's a genuinely useful trick: the difference between an 8K input OOMing your Kontext workflow and a 2MP input that just works.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| max_megapixels | FLOAT | 2.10.1–50 | — |
| only_reduce | BOOLEAN | true | — |
| interpolation | COMBO | bilinear | 7 options: nearest, linear, bilinear, bicubic, trilinear, area, +1 |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| resized_images | IMAGE | — |
| width | INT | — |
| height | INT | — |