Nodes/Steaked-nodes/Scale to Megapixels (Advanced)
ComfyUI Node

Scale to Megapixels (Advanced)

Make your upscale land on the right resolution, not a guess

By StealthNinja1O1·Created 11 months ago·Updated 5 months ago· 0
Scale to Megapixels (Advanced)
  • image
  • image
  • width
  • height
◄upscale_methodlanczos►
◄megapixels1.00►
◄width_multiple64►
◄height_multiple64►
◄keep_aspect_ratiotrue►

"Just upscale to 2 megapixels" is a sentence that only makes sense if you know what megapixels actually means for your model. SDXL wants resolutions that are multiples of 64; SD1.5 wants multiples of 8; feed either one a 937×1082 image and you'll get artifacts the model can't explain. This node is the answer to that specific, extremely common failure: it scales an image to a target megapixel count, then snaps the result to whatever multiple you specify, so the final size is both the size you asked for and the size your model can actually digest.

The math is worth understanding because it's the whole value. It counts your input's pixels, figures out the scale factor needed to hit megapixels × 1,048,576 total pixels, then rounds both dimensions to the nearest multiple of width_multiple/height_multiple. That's the "SDXL-safe" trick: 1024×1024 is 1.05 MP and a multiple of 64, so a 1 MP target lands on it cleanly instead of drifting to some non-conforming size. The upscale itself uses ComfyUI's own common_upscale, so you get the standard methods without any extra dependencies.

The inputs that matter

  • megapixels - target size, 0.01 to 16. 1.0 is a sensible default; you're usually after 1–2 for a good first pass.
  • width_multiple / height_multiple - the snapping grid. 64 for SDXL, 8 for SD1.5. Keep both on the same value unless you have a reason not to.
  • upscale_method - lanczos is the default and the right choice for plain "more pixels" work; the others are bicubic, bilinear, area, nearest-exact.
  • keep_aspect_ratio - on by default, and usually you want it that way.

Outputs are the resized image plus width and height as integers, so you can wire the exact final dimensions into an Empty Latent or a text tag without trusting yourself to do the arithmetic.

Where it fits

This is a first-rung upscaling tool, not a generative restorer. It's the "more pixels, source already sharp" category - the kind of thing that belongs before a hi-res fix or img2img pass, or when you need a latent at a model-friendly resolution. It will not invent detail; it's Lanczos-class interpolation. If you want the model to add detail, that's SeedVR2/SUPIR territory, and you'd still use something like this node to normalize your working size first. There's also a sibling node, "Scale to Megapixels (SDXL Safe)", which is this without the separate width/height multiples and without the dimension outputs - pick the Advanced one when you want the reported size back out of it.

Install

Part of Steaked-nodes:

cd ComfyUI/custom_nodes
git clone https://github.com/StealthNinja1O1/Steaked-nodes

Restart, or use ComfyUI Manager → "Steaked-nodes". No model files, no heavy dependencies - it leans on ComfyUI's own utils plus torch/numpy/Pillow.

Common issues

The classic gotcha: it snaps to the nearest multiple, so a target that's between multiples can land slightly over or under your megapixel count - that's the point, and it's fine. Set width_multiple and height_multiple to the same value or you'll silently change aspect ratio when keep_aspect_ratio is off. And if your output comes out smaller than you expected, check megapixels: the node computes total pixels, so for a non-square image, 1 MP does not mean 1000×1000.

CategorySteaked-nodes/upscaling

Inputs (6)

NameTypeDefaultDescription
imageIMAGE—
upscale_methodCOMBOlanczos5 options: nearest-exact, bilinear, area, bicubic, lanczos
megapixelsFLOAT1.000.01–16—
width_multipleINT641–512—
height_multipleINT641–512—
keep_aspect_ratioBOOLEANtrueMaintain original aspect ratio

Outputs (3)

NameTypeDescription
imageIMAGE—
widthINT—
heightINT—