Resolution Selector from Dimensions (rholdorf)
Let this node detect the aspect ratio for you
- width
- height
- aspect_ratio
Every model has resolutions it actually likes. SD 1.5 wants something near 512x512, Flux and the other 1MP-class models want 1024x1024 territory, and they all want the sides on a sane multiple. You can generate at 1013x1001 - ComfyUI won't stop you - but you'll fight quality and artifacts the whole way. ComfyUI's built-in Resolution Selector fixes the "sane size" part, except it makes you pick the aspect ratio from a dropdown, which is one step too many if your input image already tells you what ratio you want.
That's the step this node removes. Give it a reference width and height and it detects the closest of eight standard ratios (1:1, 2:3, 3:2, 3:4, 4:3, 9:16, 16:9, 21:9), then computes a target width and height from your megapixels and multiple settings - the same math the built-in node uses, minus the manual ratio picking.
How it works
The ratio detection is the part worth understanding, because it's the part that's easy to get wrong. The node compares your width/height to each candidate using log-space distance, not raw w/h. Why that matters: in linear distance, a 2:3 input looks far from a 3:2 candidate even though they're the same ratio flipped, so landscape candidates would systematically win. Log space treats 2:3 and 3:2 symmetrically. That sounds pedantic until you feed it a 1080x1920 phone shot and it comes back with a portrait resolution instead of a landscape one.
Once the ratio is chosen, it computes total pixels as megapixels × 1024 × 1024, scales the ratio's sides to that area, and snaps each side to the nearest multiple. That's the whole mechanism.
The inputs that matter
width/height- reference dimensions, and per the tooltips, only used to detect the closest aspect ratio. They don't otherwise constrain the output.megapixels- target total, default 1.0 (~1024x1024 for square). This is where you set "SD 1.5" (around 0.26) versus "1MP model" (1.0).multiple- snapping step, default 8. Bump toward 64 if you're targeting SD 1.5's grid.
Outputs are width, height, and aspect_ratio - the last one a string like "16:9 (Widescreen)", which the node also paints on its face so you can see what it picked without hovering.
In a workflow
Wire width and height into an Empty Latent Image and you've got a generation canvas that's always a sane resolution for your model, whatever ratio your source image was. It pairs naturally with the pack's Image Resize (Lanczos 3 non-separable) node, whose width/height outputs hand you the reference pair for free.
Install
This is part of the small comfyui_imgtools pack by rholdorf (11 nodes: image processing, resolution helpers, LoRA training load/save nodes, a LoRA merger). Install once, get them all:
cd ComfyUI/custom_nodes
git clone https://github.com/rholdorf/comfyui_imgtools
Then restart ComfyUI. Or search "rholdorf" in ComfyUI Manager and click install - same result. No build step, no extra Python dependencies; the pack runs on the torch/numpy/Pillow ComfyUI already ships. JS changes under web/ need only a browser refresh; Python changes need a full restart. It's a young, low-star solo pack, so treat it like any small custom node: it's MIT, the code is short and readable, and nothing here calls out to a network or needs a model download.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| width | INT | 10241–16384 | Reference width — only used to detect the closest aspect ratio. |
| height | INT | 10241–16384 | Reference height — only used to detect the closest aspect ratio. |
| megapixels | FLOAT | 1.00.1–16 | Target total megapixels. 1.0 MP ≈ 1024x1024 for square. |
| multiple | INT | 88–128 | Nearest multiple to snap the result to. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| width | INT | — |
| height | INT | — |
| aspect_ratio | STRING | — |