Image Scale Down To 1MP
Cap any image at 1MP without mangling the aspect ratio
- image
- IMAGE
This one does exactly one thing, and it's a thing you'll quietly thank it for: it takes any image and guarantees it's at or under a megapixel - 1024x1024 total pixels - while preserving aspect ratio. Feed it a 3000x2000 phone photo and it comes back at about 1250x835. Feed it an 800x600 thumbnail and it comes back unchanged, pixel for pixel, because the "at or below" part is a cap, not a resize. That pass-through behavior is the sleeper feature: it makes the node a safe floor in a batch pipeline where you never know what resolution walks in.
Why do you want a 1MP ceiling? Think of the last few places a too-big image bites you. Loading an arbitrary reference photo before ControlNet or img2img, where VRAM climbs with pixel count. Prepping a mixed-size folder for dataset work or a training run. Running a detail pass where the point is composition, not resolution. The KB's upscaling notes carry the same instinct in reverse - for a soft source, downscale first, then rebuild from a sharper-relative base. This node is that "downscale first" in one box. One honest caveat: downscaling is lossy and irreversible, so if the image already has detail you need, this isn't the tool - that's an upscaler's job, not a capper's.
The mechanism is short and boring in a good way. It reads the tensor's width and height, multiplies them, and if the total is under 1024 * 1024 it returns the input untouched. Otherwise it computes sqrt(1MP / total_pixels) as a scale factor - the way to shrink both dimensions and land right at the target pixel count - rounds, and nudges dimensions down until the product fits under the cap. It uses ComfyUI's own common_upscale with cropping disabled, so aspect ratio survives. The one parameter besides the image is upscale_method, which despite the name is really "which interpolation," defaulting to lanczos - a solid choice for this job, sharper than bicubic. area is the pixel-averaging option, good if you're downscaling something destined to be squinted at; nearest-exact is for pixel-art. In practice, leave it on lanczos.
Inputs, all two of them:
- image - any
IMAGEtensor. - upscale_method -
lanczosdefault; the other four arenearest-exact,bilinear,area,bicubic.
One IMAGE out, wired into whatever wants a capped image next.
Install is the pack's one-liner. ComfyUI Manager, search comfyui-uonr-nodes, or:
cd ComfyUI/custom_nodes
git clone https://github.com/uonr/comfyui-uonr-nodes
Restart and you're done. No models, no dependencies, nothing to configure - the README is four bullet points and the pack calls itself personal nodes, which is the right amount of ambition for a node this focused.
One thing to know: it works in pixel space and doesn't snap results to multiples of 8 or 64. If you pipe the output straight into VAE encode for img2img, the latent round-trips to the nearest multiple anyway, so it's rarely a problem - but if you need exact 64-multiple dimensions for a generation bucket, reach for a latent-side node instead. For capping refs and prepping inputs, this just works.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| upscale_method | COMBO | lanczos | 5 options: nearest-exact, bilinear, area, bicubic, lanczos |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | The original image when it is at or below 1024x1024 pixels, otherwise a downscaled image. |