DJZ Scale to Total Pixels
Scale to an exact megapixel budget, always divisible by 64
- image
- IMAGE
Here's a problem you've definitely hit: you want an image that lands at roughly 1 megapixel, or exactly 1.5MP for a given model, and every resize node forces you to think in width×height. DJZImageScaleToTotalPixels inverts that - you tell it a megapixel budget and it figures out the dimensions. It's the "scale to total pixels" utility from DJZ-Nodes, and it's quietly one of the most useful little nodes in the pack for anyone who works across multiple models with different pixel-count sweet spots.
How it works
The math is straightforward and it's the same logic ComfyUI uses internally: it computes a scale factor from sqrt(total_pixels / (width * height)), applies it to both dimensions, then rounds each to the nearest multiple of downscale_factor (default 64). That rounding is the whole point - models and many pipelines want dimensions divisible by 64 (or 8/16/32), and getting that for free is why you use this instead of a raw resize.
Inputs: image (IMAGE), upscale_method (nearest-exact, bilinear, area, bicubic, or lanczos - pick lanczos for upscaling, area for downscaling), megapixels (0.01-16, default 1.0), and downscale_factor (1-512, default 64). The node uses ComfyUI's common_upscale, so it's the same quality path as the core image upscale node, with cropping disabled. It guarantees a minimum dimension of one downscale_factor, so you never get a degenerate 8×8 output from a tiny target.
Output: the resized IMAGE.
What people actually use it for
- Normalizing a mixed batch of images to the same pixel budget before a model that cares about total pixels (SDXL likes ~1MP, SD likes ~0.5MP, Cascade-class likes a lot more).
- Setting a consistent source resolution for video frame processing.
- Pre-scaling for upscaling pipelines where you want a predictable middle size.
Installing
Part of DJZ-Nodes (Drift Johnson / MushroomFleet):
cd ComfyUI/custom_nodes
git clone https://github.com/MushroomFleet/DJZ-Nodes
cd DJZ-Nodes
pip install -r requirements.txt
Or search "DJZ-Nodes" in ComfyUI Manager. Uses only ComfyUI internals, zero extra deps.
Gotchas
The rounding means you rarely land exactly on your megapixel number - a 1024×1024 image at 1.0MP rounds to 1024×1024, but an odd aspect image might land at 1.02MP. That's fine; the point is the budget, not the last decimal. And remember it's a pixel-budget node, not a model: it upscales or downscales with plain interpolation, so it adds no detail. The KB's upscaling essay makes the distinction that pixel-adding and detail-inventing are different jobs - this one is firmly in the "more pixels, no hallucination" camp. If your image is already the size you want, a no-op resize still costs a little quality; pass it through with megapixels set to your current total if you must.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| upscale_method | COMBO | 5 options: nearest-exact, bilinear, area, bicubic, lanczos | |
| megapixels | FLOAT | 1.000.01–16 | — |
| downscale_factor | INT | 641–512 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |