Scale SDXL Image MXD
Scale to a megapixel count and land on an SDXL-safe size
- image
- IMAGE
Here's a common img2img situation: you've got an image at some arbitrary size, you want to work on it in SDXL, and you want it to be about a megapixel - because that's the resolution SDXL was trained at and where it behaves itself. The core ImageScaleToTotalPixels node does exactly this: pick a target megapixel count, keep the aspect ratio, done. Scale SDXL Image MXD is that node with a SDXL-flavored twist - if your image is already at one of the five SDXL-safe resolutions, it passes it straight through untouched rather than resampling for no reason.
Why the "SDXL safe" framing exists
SDXL's five training resolutions (1024², 1152x896, 1216x832, 1344x768, 1536x640) are where the model is happiest, and the community has internalized that going far outside them costs quality. This node encodes two bits of that wisdom: it knows those sizes, and it refuses to nudge an image that's already there. So when you're prep an input before a generation or a detail pass, you get the target-megapixel convenience and a guard against pointless resampling.
How it works
The math is ComfyUI's standard megapixel scaling, which is as clean as it gets:
- Compute
scale_by = sqrt(target_pixels / (width * height))- a single factor for both axes, so aspect ratio never distorts. - Resize with your chosen
upscale_method(bilinear default; bicubic and lanczos are the other sane picks). - If the input already matches an SDXL-safe resolution (in either orientation), return it unchanged.
One deliberate quirk: the node hard-rejects nearest-exact and area as upscale methods with an error telling you to pick something like lanczos. It's a blunt hint, but a fair one - those two give visibly worse results for this job.
Inputs and outputs
- image - what you're scaling.
- total_megapixels - the target, as a float (1.0 = 1MP). Default 1.0 is the SDXL sweet spot.
- upscale_method - bilinear / bicubic / lanczos (use these) or the two it'll refuse.
- Output: IMAGE, ready to feed a sampler at the right footprint.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/Maxed-Out-99/ComfyUI-MaxedOut.git
Restart, or ComfyUI Manager → search "Maxed Out" → install. No model downloads - this is plain tensor resampling, nothing generative.
Troubleshooting
- "nearest-exact/area gives poor results" - that's the node refusing a bad choice, not a bug. Switch to lanczos.
- Image comes back the same size when you expected it to change - it was already an SDXL-safe resolution, so it skipped. If you genuinely need a different size, change the target megapixels.
- Aspect ratio drifts slightly -
round()can make the output a pixel or two off from exact. That's normal and harmless for img2img.
One honest caveat: this is a pixel resize, not a detail upscale. If your goal is "make it bigger AND add detail," you want a generative upscaler (SeedVR2/SUPIR territory), not this. For getting an image onto SDXL's home turf, it's exactly right.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| upscale_method | COMBO | bilinear | 5 options: bilinear, bicubic, lanczos, nearest-exact, area |
| total_megapixels | FLOAT | 1.000.01–128 | Set the total megapixels (e.g., 1.0 = 1 MP) |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |