Nodes/comfyui-art-venture/Scale To Megapixels
ComfyUI Node Runs on cloud

Scale To Megapixels

ImageScaleToMegapixels — resize an image to a target pixel budget, not a fixed width

By sipherxyz·Created 3 years ago·Updated 4 months ago· 352
Scale To Megapixels
  • images
  • upscale_model_opt
  • IMAGE
megapixels1.00

Most resize nodes make you pick a width and a height. This one asks a smarter question: how many total pixels do you want? You give it a megapixel target, it works out the width and height that hit that budget while keeping the original aspect ratio. That's the whole idea, and it's more useful than it sounds.

Here's why you'd reach for it. Diffusion models have a resolution they were trained at - SD 1.5 is happiest around 0.26MP (512×512), SDXL and Flux around 1MP (1024×1024). Go far above that and you get duplicated limbs, repeated faces, the whole "two heads" mess. The problem is your input images come in every aspect ratio under the sun. A 3:2 photo, a 9:16 phone screenshot, a square crop - each needs a different width and height to land at ~1MP. Computing that by hand every time is tedious. Set megapixels to 1 and this node does it for any input, no math on your part.

How it works

Megapixels is just width × height ÷ 1,000,000. The node inverts that: given your target and the image's current aspect ratio, it solves for the new dimensions and resamples the image to fit. By default that's a normal interpolation resize (think Lanczos-quality downscaling or upscaling). It's a geometry calculator wrapped around a resize - no model, no invented detail, unless you give it one.

The inputs and outputs that matter

  • images - the image (or batch) to resize.
  • megapixels - your target pixel budget, default 1, range 0.1100. For SDXL/Flux latent-space work, 1 is the sweet spot. Drop to 0.25 for SD 1.5.
  • upscale_model_opt (optional) - plug in an UPSCALE_MODEL (an ESRGAN-family upscaler loaded elsewhere) and the resize routes through it instead of plain interpolation. This only helps when you're scaling up - an ESRGAN model invents plausible detail where interpolation just smears. Scaling down, leave it empty.

Output is a single IMAGE at the new size, ready to feed a VAE encode, a ControlNet preprocessor, or whatever's next.

One thing worth knowing from the upscaling world: "upscale" means three different jobs - more pixels, more detail, or more pixels over time (video). This node does the first, and optionally the second if you hand it a model. It won't restore a soft image on its own; interpolation can't hallucinate detail that was never there.

How to install it

It's part of the Art Venture pack. Easiest path is ComfyUI Manager → search comfyui-art-venture → Install → restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/sipherxyz/comfyui-art-venture

then pip install -r comfyui-art-venture/requirements.txt and restart ComfyUI. No model download for this node itself - the optional upscale model is loaded by a separate loader node and passed in.

Common issues & troubleshooting

The output isn't exactly your target. It won't be, and that's fine. Pixel dimensions are integers, so the node rounds to the nearest whole width and height that preserves the ratio. You'll land a hair under or over the exact megapixel count. Nothing to fix.

Upscaling looks soft. If you're scaling up without an upscale_model_opt, you're just interpolating - it'll be blurry by nature. Load an ESRGAN-style model (4x-UltraSharp, RealESRGAN) and wire it into the optional input, or do a proper detail-adding pass (tile ControlNet, SUPIR) afterward if you actually need new detail rather than more pixels.

Node's missing after importing someone's workflow. That's the number-one Art Venture complaint - a shared workflow references the pack and you don't have it. Open Manager → Install Missing Custom Nodes and it'll pull the whole pack in one go.

CategoryArtVenture/Utils

Inputs (3)

NameTypeDefaultDescription
imagesIMAGE
megapixelsFLOAT1.000.1–100
upscale_model_optoptUPSCALE_MODEL

Outputs (1)

NameTypeDescription
IMAGEIMAGE