Nodes/ComfyUI-Qais-Helper/QH: Nearest SDXL Resolution
ComfyUI Node

QH: Nearest SDXL Resolution

Snap any image to a real SDXL resolution without doing the math

By QaisMalkawi·Created 3 years ago·Updated 6 months ago· 2
QH: Nearest SDXL Resolution
  • image
  • width
  • height

The name is the whole pitch: feed it an image and it tells you the closest SDXL-native resolution. "QH: Nearest SDXL Resolution" is one of the more genuinely useful things in the QaisHelper pack, because almost everyone hits the problem it solves at some point.

Here's the thing about SDXL that burns people: it wasn't trained on arbitrary resolutions. It was trained on nine specific aspect ratios - 1024x1024, 1152x896, 896x1152, 1216x832, 832x1216, 1344x768, 768x1344, 1536x640, and 640x1536. Generate somewhere between those and you get the classic stretched-anatomy failures: double heads, elongated bodies, that "why does everything look wrong" feeling. The fix is to generate at a trained ratio and upscale afterward, not to fight the model at 1920x1080.

So when you're doing img2img from a reference image and you want to re-generate at a resolution SDXL actually likes, this node does the lookup for you. You drop in whatever image, it computes the aspect ratio, finds the closest trained one, and hands you the width and height.

How it works

Under the hood it's about as simple as it gets. The node reads the image tensor, extracts width and height, computes the ratio (width over height), then measures the difference between that ratio and each of the nine baked-in SDXL ratios. The closest match wins, and it returns those dimensions as two integers. It also prints the input image's resolution to the console as a side effect.

The one thing worth internalizing: it matches on aspect ratio, not pixel size. A 256x256 thumbnail and a 2048x2048 full-res copy of the same composition are the same ratio, so they both snap to the same SDXL resolution. That's usually exactly what you want for img2img. If you actually wanted to preserve absolute size, this isn't the node - it's answering "what ratio should I be using," not "how big is this image."

Inputs and outputs

Just one input, and it's the obvious one:

  • image - any IMAGE, i.e. the output of a Load Image node or anything that produces an image tensor.

And two outputs, both integers:

  • width
  • height

Wire those into an EmptyLatentImage (or any node with width/height inputs) and you're generating at a proper SDXL ratio. That's the natural loop: load reference → snap to nearest SDXL resolution → empty latent at that size → img2img.

Installing it

This is a small pack with a single dependency (numpy), so there's nothing scary here:

  • ComfyUI Manager - search for "ComfyUI-QaisHelper" (or just "Qais Helper") and hit Install. It's registered with the Comfy Registry, so Manager finds it.
  • Manual - cd ComfyUI/custom_nodes && git clone https://github.com/QaisMalkawi/ComfyUI-QaisHelper, then restart ComfyUI.

No model files to download, no extra pip packages beyond numpy. The whole pack is a handful of utility nodes that run on import, so the risk surface is minimal - but it's from a first-time pack author, so don't be surprised if the code style is on the casual side.

Common gotchas

The main one is expectation-setting: this node outputs numbers, not a latent or an image. If you wire it up and nothing happens, check that you've actually connected width and height somewhere that consumes integers. And remember it's a ratio matcher - a 16:9 reference won't give you 1920x1080; it'll give you 1344x768, because that's the closest trained SDXL aspect. Generate there, then upscale. That's not a bug, it's the whole point.

CategoryQais Helper/Graphics

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (2)

NameTypeDescription
widthINT
heightINT