NearestSDXLExtendedResolution
Find the right SDXL size from an image
- image
- width
- height
SDXL is picky about what shape it generates well at, and if you've ever tried to upscale or reprocess an odd-sized image through it, you already know the annoyance: you either eyeball a "close enough" resolution off a chart, or you write down the numbers wrong and get a slightly warped result. NearestSDXLExtendedResolution does that lookup for you - hand it an image, get back the closest SDXL-friendly width and height as plain integers you can plug straight into a resize or an empty latent.
It's part of ComfyMath, evanspearman's small math-and-logic node pack, and this is genuinely one of the pack's more-used nodes in the wild - people reach for it specifically to avoid hand-matching resolution tables during upscale workflows.
How it works
You feed it an image, and internally it measures that image's dimensions and matches them against ComfyMath's own extended table of SDXL-shaped resolutions, returning the entry closest to your input's aspect ratio. It's the same idea as SDXL's official multi-aspect training buckets - 1024x1024, 1152x896, 1216x832, 1344x768, 1536x640, and their rotations - except this "Extended" variant works from a much larger table (the sibling dropdown node, CM_SDXLExtendedResolution, exposes the full list directly). Every entry in that table holds roughly the same total pixel budget as SDXL's native 1024×1024, just sliding the aspect ratio across many more steps than the five official ratios cover.
That matters for a common real workflow: take a depth map, a ControlNet input, or a first-pass generation at an arbitrary size, run it through this node, and use the output width/height to drive an upscale or re-render at a size SDXL will actually behave well at - instead of stretching the image to whatever size you had in mind and getting elongated anatomy or double heads for your trouble.
Inputs and outputs
image(IMAGE) - the image whose dimensions get matched against the resolution table.- Outputs:
widthandheight(INT, INT) - wire these straight into a Resize/Upscale node's width/height, or into an Empty Latent Image if you're regenerating at that size.
How to install it
Through ComfyUI Manager: search ComfyMath, install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/evanspearman/ComfyMath.git
then restart ComfyUI. No dependencies beyond ComfyUI itself, no model files - it's a lookup table and some arithmetic.
Common issues & troubleshooting
You have width/height, not an image, and the node won't accept them. This node specifically wants an IMAGE tensor as input - it measures the image itself rather than taking numbers. If all you have are two integers, use CM_SDXLExtendedResolution instead, which is the dropdown version that doesn't need an image at all.
The output resolution looks like an unusual shape. Because this is the extended table rather than SDXL's core five trained ratios, some matches will land on aspect ratios well outside what SDXL actually saw in training - the further from square the match, the more likely you are to see soft distortion or stretched anatomy. If you want to stay strictly within the officially trained ratios, cross-check the result against 1024x1024 / 1152x896 / 1216x832 / 1344x768 / 1536x640 (and rotations) rather than trusting every extended entry equally.
The pack looks unmaintained. A 2024 community thread noted the author had moved on from active development, though the same thread confirmed the node works as intended - outputting the correct nearest resolution when tested against a real image. It's a stable, finished utility rather than something with ongoing feature work; that's fine for a lookup table this simple.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| width | INT | — |
| height | INT | — |