Nodes/CRT-Nodes/Image Scale Range From MP (CRT)
ComfyUI Node

Image Scale Range From MP (CRT)

Keep every image in a batch between two megapixel bounds

By PGCRT·Created 2 years ago·Updated a day ago· 132
Image Scale Range From MP (CRT)
  • image
  • image
  • width
  • height
upscale_method
min_megapixels0.25
max_megapixels1.00
resolution_steps1

Upscale is a one-way street: once an image is too big for your workflow, scaling it back down loses the point. ImageScaleRangeFromMp is the node that thinks in megapixels instead - you give it a floor and a ceiling, and it normalizes whatever comes in to sit between them. In a batch where inputs vary from tiny thumbnails to wallpapers, it's the difference between a sampler that chokes on mixed resolutions and one that never notices.

The mechanism, and why it's smart about it

It measures the incoming image, and:

  • below min_megapixels → upscales to the floor
  • above max_megapixels → downscales to the ceiling
  • already in range → passes through untouched

The scaling is the part worth reading twice: it resizes both axes by one uniform factor (so no aspect-ratio stretch), then does the final quantization with a centered crop, never a second resize. That crop-first approach means the output stays step-aligned without the softness a second interpolation pass would add. Small downside to know: because it crops down, the final megapixels can land slightly below the bound you asked for.

The inputs

  • image - your IMAGE tensor.
  • upscale_method - nearest-exact, bilinear, area, bicubic, or lanczos. For downscaling, area is the classic pick; for upscaling, lanczos/bicubic look better than nearest.
  • min_megapixels - floor (default 0.25).
  • max_megapixels - ceiling (default 1.0).
  • resolution_steps - the step to quantize the final dimensions to (default 1, so no quantization). Set it to 8 or 16 if your sampler needs multiples.

Outputs: the resized image, plus width and height as INTs - the pair you can wire into a KSampler's EmptyLatentImage or into CRT's own Resolution (CRT) world.

Where you'd reach for it

Mixed-resolution batches, mostly - a folder of reference images, video frames, or scraped data where every input is a different size and the downstream model has a sweet spot. It's also a handy normalization layer before an upscale pass: clamp inputs to a sane MP range so the heavy model only sees what it's good at. It is not a quality upscaler - it's a range normalizer with good taste.

Gotchas

  • Cropping, not stretching. If you need every pixel preserved, this will center-crop edges instead. Know that going in.
  • Tiny inputs get upscaled with real interpolation. min_megapixels above the source size means invented pixels, not recovered detail - keep the floor close to your actual content.
  • Step 1 = no quantization. The default resolution_steps of 1 is fine for most downstream nodes, but model-specific multiples (8/16/64) are your job to set.

Install CRT-Nodes via ComfyUI Manager (CRT-Nodes) or git clone https://github.com/plugcrypt/CRT-Nodes.git into custom_nodes, install requirements.txt, restart.

CategoryCRT/Image

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
upscale_methodCOMBO5 options: nearest-exact, bilinear, area, bicubic, lanczos
min_megapixelsFLOAT0.250.01–64
max_megapixelsFLOAT1.000.01–64
resolution_stepsINT11–256

Outputs (3)

NameTypeDescription
imageIMAGE
widthINT
heightINT