Nodes/Y7Nodes for ComfyUI/Y7 Scale Image to Total Pixels
ComfyUI Node

Y7 Scale Image to Total Pixels

Set a pixel budget, not a size — the megapixel-normalizing resize node

By yushan777·Created about a year ago·Updated 4 days ago· 8
Y7 Scale Image to Total Pixels
  • image
  • image
  • width
  • height
upscale_methodlanczos
megapixels1.00
resolution_steps8

Most resize nodes make you say how big. Y7 Scale Image to Total Pixels makes you say how many pixels - you set a megapixel budget, it does the geometry, and every image that passes through comes out at roughly the same total regardless of aspect ratio. A 16:9 landscape and a 3:4 portrait both hit ~1.0 MP; they just aren't the same width and height.

That's a genuinely different way to think about resizing, and it's the right one for a few specific jobs.

Why you'd reach for it

  • Normalizing a mixed batch. If you're captioning or tagging a folder of images with a vision model, feeding them all at the same pixel budget gives every image equal treatment instead of letting a 12MP photo dominate.
  • Training-data prep. Standardizing to a target megapixel count is a classic step before LoRA or fine-tune data processing - you want consistent resolution, not consistent width.
  • Hitting a model's comfort zone. ~1 megapixel (1024×1024 for square) is the sweet spot most diffusion backbones and image-LLMs were tuned around. If a workflow keeps producing images at 2.3MP and your model drifts, this node brings them back under budget.

How it works

The mechanism is where it earns the name. It takes your megapixels target, converts to a raw pixel count (megapixels × 1024 × 1024), then computes a uniform scale factor as sqrt(total / (width × height)) - the single multiplier that makes the current image's area equal your target while keeping the aspect ratio intact. Then it snaps each dimension to resolution_steps and resamples through ComfyUI's common_upscale. The resulting W x H is stamped on the node after the run.

One thing worth knowing: the snapping happens after the scale factor is computed, so the actual result is "as close as rounding allows," not a perfect hit. At steps of 8 the drift is a handful of pixels either way. Fine for every practical use.

The inputs that matter

  • megapixels - the budget, 0.01 to 16.0, default 1.0. That default is well-chosen: it's the natural "about a megapixel" target.
  • resolution_steps - default 8, same snapping logic as its sibling Y7 Scale Image By. Raise to 16 or 64 if your downstream model needs stricter multiples.
  • upscale_method - default lanczos. Good for growing; if you're shrinking a large source down to budget, area handles the downsampling more cleanly.

Outputs are the resized image plus width and height as INTs, so you can wire the actual result dimensions onward instead of assuming them.

Installing it

It's part of ComfyUI-Y7Nodes ("Y7Nodes for ComfyUI"). ComfyUI Manager → Custom Nodes Manager → search Y7Nodes → Install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/yushan777/ComfyUI-Y7Nodes
pip install -r requirements.txt

The requirements install transformers, sentencepiece, lmstudio and friends because the pack also contains heavy LLM nodes - the resize node itself is plain ComfyUI, no model downloads.

Where people trip up

The usual disappointment: setting 1.0 megapixels on a small, soft image and expecting detail. That's interpolation, not generation - you're redistributing pixels that already exist, and the upscaling rule still applies: "more pixels" and "more detail" are different jobs. If you actually want to restore detail, pair this node with a real detail-adder afterward rather than asking it to do both.

CategoryY7Nodes/Image

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
upscale_methodCOMBOlanczos5 options: nearest-exact, bilinear, area, bicubic, lanczos
megapixelsFLOAT1.000.01–16
resolution_stepsoptINT81–256

Outputs (3)

NameTypeDescription
imageIMAGE
widthINT
heightINT