Ratio to Size 988
Turn an aspect ratio and a megapixel count into clean dimensions
- width
- height
- info
"Generate it at 16:9, about a megapixel." That sentence is a math problem, and the math has a trap: diffusion models and their VAEs want dimensions that divide cleanly - multiples of 64 for the SDXL/Flux lineage, or the VAE and the sampler get grumpy (the KB's troubleshooting doc calls out tiling/repetition artifacts when you push past what a model handles). Ratio to Size 988 is the node that turns your ratio-and-size wish into width/height numbers that respect that constraint.
How it works
You pick an aspect ratio (16 entries in the dropdown, covering the portrait and landscape families: 1:1, 5:4, 4:3, 3:2, 16:9, 2:1, 21:9, 32:9 and their portrait mirrors), a target megapixel budget (default 1.05, range 0.1–3), and a precision tolerance. It solves for width and height at your megapixel target, then snaps both to multiples of 64, iterating down until the resulting ratio is within precision of the true aspect ratio. The output is a pair of integers that are actually usable - no 1021×574 nonsense.
The inputs that matter
ratio- the shape you want. The dropdown entries even carry a little glyph (▭ for landscape, ▯-ish for portrait) so you can tell orientation at a glance.megapixel(default 1.05) - total pixel budget. 1.05 is a sensible SDXL default (that's ~1024×1024); crank it for higher-res generations, within what your card and the model can actually do.precision(default 0.3) - how close the snapped dimensions must match the true ratio. Higher precision = stricter aspect fidelity but it may push you to a smaller/larger total size to make the multiples-of-64 math work. If you've ever gotten 1024×576 when you wanted 16:9 and found the aspect slightly off, this is the dial that trades size for exactness.
Outputs
widthandheight- INT, multiples of 64. Wire these into whatever expects dimensions: a latent size node, an empty latent, a resolution selector.info- a text summary (ratio, width, height, actual megapixels) for eyeballing; feed it to Display UI 988 if you want it visible.
Why you'd reach for it
Every time you type a resolution by hand, you're doing this node's job with a calculator and getting it subtly wrong. The sane pattern: pair it with Ratio Calculator 988 - read the source image's ratio, feed it into this node's ratio input (the dropdown also accepts a wired string), pick your megapixels, and get clean dimensions for the generation pass. It's the "pick a canvas the model actually likes" node, which the KB's concepts guidance backs up: match the model's native training shape rather than inventing one.
Gotchas
- The result is snapped to multiples of 64, so actual megapixels won't exactly match the target - that's the point of
precision, but readinfoif you care about the exact number. precisionof 0 gives the strictest ratio match but can shrink the image more; 0.3 is the author's default for a reason. If your output looks oddly small, loosen precision or raise megapixels.
Install
Part of ComfyUI-988: Manager (search "ComfyUI-988") or:
cd ComfyUI/custom_nodes
git clone https://github.com/kajan988/ComfyUI-988
cd ComfyUI-988
pip install -r requirements.txt
Then restart. No models, no downloads - just arithmetic that respects the VAE.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| ratio | COMBO | 16 options: 1:1 ◻, 5:4 ▭, 4:3 ▭, 3:2 ▭, 16:9 ▭, 2:1 ▭, +10 | |
| megapixel | FLOAT | 1.050.1–3 | — |
| precision | FLOAT | 0.300–1 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| width | INT | Optimal width (multiple of 64) |
| height | INT | Optimal height (multiple of 64) |
| info | STRING | Summary of selected parameters |