NearestSDXLResolution
Feed it any image, get the closest SDXL bucket
- image
- width
- height
This is the more useful sibling of SDXLResolution, and it's the one node in this whole pack with an actual community following: it takes an image of any size and outputs the SDXL-trained resolution whose aspect ratio is the closest match. One Reddit user calling it "a really cool feature" described using it for image upscaling without "the hassle of compar[ing] the lists and chang[ing] values" by hand - feed in a source image, get back the right target resolution to work at, no lookup table required.
Where you'd actually use it: an img2img or hi-res-fix pipeline where the input image's dimensions aren't something you control (a user upload, an odd crop, a non-standard source), but you still want to do the actual SDXL denoising pass at one of the resolutions the model was trained on rather than whatever arbitrary size the source happens to be.
How it works
Feed it an image. It reads that image's dimensions, compares the aspect ratio against SDXL's fixed set of trained buckets (1024x1024, 1152x896, 1216x832, 1344x768, 1536x640, and their rotations), and outputs the closest one as width/height.
The inputs and outputs that matter
- image - the source image; only its dimensions matter, not its content.
- Outputs - width and height, both INT, the nearest SDXL-trained resolution - feed straight into an Empty Latent Image, an upscale node's target size, or a resize step.
Installing it
ComfyUI Manager: search ComfyMath, install, restart. Or by hand:
cd ComfyUI/custom_nodes && git clone https://github.com/evanspearman/ComfyMath
then restart. Pure Python, no dependencies beyond ComfyUI's own, nothing to download.
Common issues
The real trap isn't with this node, it's with what people chain after it. One Reddit thread walks through exactly this: combining NearestSDXLResolution with a separate "recommended resolution calculator" node from a different pack, expecting the second node to automatically compute the upscale factor needed to reach a target size. It didn't - the second node just echoed back whatever upscale multiplier the user typed in, doing nothing useful with the resolution this node fed it. The lesson isn't specific to that combo: don't assume two calculator-style nodes from different packs will compose the way their names imply. Check what each one's inputs and outputs actually mean before trusting the chain, especially with nodes this thinly documented.
It's also worth being clear this only outputs the aspect-ratio-nearest bucket, not one that preserves your original resolution or scale - the output dimensions can be quite different in absolute size from your source image, by design. If you need to keep the original scale and just correct the aspect ratio, you'll want to combine this with an explicit crop or resize step, not assume the output is a drop-in resize target.
Same maintenance note as the rest of ComfyMath: no active development since roughly early 2024 per community reports, but as a small, dependency-free bit of arithmetic on trained values that haven't changed since SDXL shipped, that inactivity hasn't hurt this node's usefulness.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| width | INT | — |
| height | INT | — |