Nodes/comfyui-latent-astronaut-suite/Image Resize to Total Pixels
ComfyUI Node

Image Resize to Total Pixels

Resize to a pixel budget, not a resolution

By latentastronaut·Created 8 months ago·Updated 7 months ago· 2
Image Resize to Total Pixels
  • image
  • image
  • width
  • height
megapixels1.00
increment16
resize_methodstretch
interpolationlanczos

Most resize nodes make you pick a width and a height. Image Resize to Total Pixels flips the question: instead of "what resolution," you say "I have this many megapixels to spend," and the node figures out the dimensions. It's the right tool when you're targeting a model's pixel budget - say, a video model or trainer that wants "~1 MP per frame" - or when you have images of wildly different aspect ratios that all need to land at the same compute cost.

How it works

The math is straightforward and the code shows it. Given a target megapixels value, it computes target pixels (megapixels × 1,000,000) and solves for dimensions while preserving your aspect ratio: width = √(pixels × aspect), height = √(pixels ÷ aspect). Then it rounds both dimensions up to a multiple of increment, which defaults to 16 - the classic diffusion-friendly constraint. Two resize modes follow: stretch just forces the image to those dimensions (aspect ratio drifts slightly because of the rounding), while crop resizes to cover the target and center-crops, keeping your aspect ratio intact. Interpolation defaults to lanczos, with bicubic, bilinear, and nearest as alternatives.

The inputs that matter

  • image (required) - a batch of images; the whole batch gets resized identically
  • megapixels - target size, 0.01 to 100, default 1.0
  • increment - dimension rounding, default 16
  • resize_method - stretch (distorts slightly) or crop (preserves aspect)
  • interpolation - default lanczos

Outputs are image, plus width and height as separate INTs. Those two integers are genuinely useful: you can wire them into a latent's dimensions or a video node's frame size, so whatever you resize to, the generation side matches.

When to reach for it

The sweet spot is batch and video work. Say you're feeding frames of mixed aspect ratios into a video model that wants a fixed pixel count per frame - set megapixels once and every frame costs the same, no per-frame resolution fiddling. It's also handy for image2video pipelines that want "Flux-ish" input budgets. If you just want to upscale to a specific resolution, a normal resize node is simpler; this one pays off when the pixel budget is the constraint, not the resolution.

Install and quirks

Standard pack install - ComfyUI Manager, search "Latent Astronaut Suite," or:

cd ComfyUI/custom_nodes
git clone https://github.com/latentastronaut/comfyui-latent-astronaut-suite

Restart. No extra dependencies; this node is pure torch + PIL. One thing worth knowing: stretch mode's aspect distortion is usually invisible because the increment rounding is small, but if you're resizing a face or text, crop is the safer default - it never distorts, just trims edges. And if you want pixel-perfect multiples for a finicky model, bump increment to 32 or 64 rather than fighting the rounding.

Categoryimage/latent-astronaut

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
megapixelsFLOAT1.000.01–100Target size in megapixels (1.0 = 1,000,000 pixels)
incrementINT161–256Dimensions will be multiples of this value
resize_methodCOMBOstretchStretch distorts aspect ratio; crop maintains it
interpolationCOMBOlanczos4 options: lanczos, bicubic, bilinear, nearest

Outputs (3)

NameTypeDescription
imageIMAGE
widthINT
heightINT