Best-Res (area)
Pick your resolution by megapixels instead
- width
- height
Every diffusion model has a "view window" - a total resolution it was trained on. Go way off it and you get doubled anatomy, elongated bodies, tiled patterns. That's the single most common reason a well-prompted image comes out wrong, and the fix is boring: stay near the training resolution. SD 1.5 trained on 512x512. SDXL trained on 1024x1024. The catch is that nobody wants to do the math of "how big are the two sides of a 16:9 image that has the same total pixels as a 1024x1024 square, while staying a multiple of 8?"
Best-Res (area) does exactly that arithmetic. The author calls it "THE way" to pick a resolution for diffusion models, and I tend to agree - it's the node from this pack I'd actually reach for first.
How it works
You give it a square_size (the side of the square image your model was trained on), an aspect ratio, and an orientation. It normalizes the ratio to unit area, multiplies by square_size to get float width/height, then rounds both sides so they're divisible by step - while picking the rounded pair whose aspect ratio is closest to what you asked. The output width × height lands as close to square_size² total pixels as the step allows. No stretching, no ratio drift, just "as close as possible, with step winning every tie."
The inputs you actually set
square_size- the model's native square. 1024 for SDXL/Flux, 512 for SD 1.5. Flux is flexible, but 1024 is still the sane center of its band.step- the divisibility requirement. Default 48, and the tooltip explains why: 48 = 8 × 2 × 3, which is divisible by 8 (the latent downscale factor for SD1.5/SDXL/Flux), and stays clean after a 1.5x or 1.333x upscale, and stays clean after a later 2x. If you never upscale in latent space,step= 8 is fine. If you only ever plan a 1.5x hi-res fix, 32 (8×2×2) covers you. The 48 default is the "I might do anything later" choice.landscape- ON makes width the long side, OFF makes height the long side.aspect_a/aspect_b- the ratio, e.g. 16 and 9. Order doesn't matter; orientation is the toggle's job.
Outputs are just width and height as INTs. Wire them straight into an Empty Latent Image (or a conditioning/KSampler size input), and you never hand ComfyUI a raw number again.
Why you'd reach for it
Two cases. First, you want to generate at a non-square ratio but keep total pixels at the training size - 1344x768 for SDXL is 1.03MP, which is why it's on the official trained-ratio list; this node generalizes that for any ratio. Second, you want a ratio that isn't a trained one (16:9), and you'd rather let the node find the closest clean step-compatible size than type a guess and get a "multiple of 64" warning from the VAE. The model-agnostic framing is the nice part: you tell it one number per model, and if you switch from SDXL to a future model, you change one field.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/Lex-DRL/ComfyUI-BestResolution
or search "Best Resolution" in ComfyUI Manager, install, restart. Only dependency is frozendict. No models, no weights - this node is pure arithmetic on numbers, which is exactly why it "works with any model."
One caveat: it calculates, it doesn't draw. The output is two integers. If you were hoping for a preview, you're looking at the wrong node - but that's the point. The pack philosophy is "do one thing well," and this node's one thing is the math.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| square_size | INT | 10241–9223372036854776000 | The total resolution of the image would be the same as of a square with this side. The width and height would be such to respect aspect ratio, but also be as close as possible to the total number of pixels as in this square image. - 512x512 square (SD 1.5): ~0.25 megapixels - 1024x1024 square (SDXL): ~1 megapixel |
| step | INT | 481–9223372036854776000 | Both width and height will be divisible by this value - by rounding them to the closest appropriate resolution. The default 48 is (8 * 3 * 2), so it's a safe choice because: - it's compatible with SD1.5/XL downsampling factor (divisible by 8), - it can be upscaled by x1.5 or x1.333 at the first iteration, which is optimal for latent-upscale, - after x1.5 upscale, if you only do x2 later (it's OK for already high resolutions) - it will be divisible by 3 AND 9, which might become handy at that point, where you'll probably use UltimateSDUpscale. Other values worth trying first: 64, 96, 128. |
| landscape | BOOLEAN | true | Specifies image orientation: When ON, width is bigger (image is horizontal). When OFF, height is bigger (image is vertical). |
| aspect_a | FLOAT | 16 | Two aspects together define an aspect ratio (16:9, 4:3, etc). Order doesn't matter: image orientation is defined by the 'landscape' toggle. The specified aspect ratio is APPROXIMATE: step parameter has priority over the exact image proportions. |
| aspect_b | FLOAT | 9 | Two aspects together define an aspect ratio (16:9, 4:3, etc). Order doesn't matter: image orientation is defined by the 'landscape' toggle. The specified aspect ratio is APPROXIMATE: step parameter has priority over the exact image proportions. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| width | INT | — |
| height | INT | — |