Nodes/comfyui_imgtools/Resolution Selector from Dimensions (rholdorf)
ComfyUI Node

Resolution Selector from Dimensions (rholdorf)

Let this node detect the aspect ratio for you

By rholdorf·Created 8 months ago·Updated 2 days ago· 0
Resolution Selector from Dimensions (rholdorf)
    • width
    • height
    • aspect_ratio
    width1024
    height1024
    megapixels1.0
    multiple8

    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.

    Categoryrholdorf/utils

    Inputs (4)

    NameTypeDefaultDescription
    widthINT10241–16384Reference width — only used to detect the closest aspect ratio.
    heightINT10241–16384Reference height — only used to detect the closest aspect ratio.
    megapixelsFLOAT1.00.1–16Target total megapixels. 1.0 MP ≈ 1024x1024 for square.
    multipleINT88–128Nearest multiple to snap the result to.

    Outputs (3)

    NameTypeDescription
    widthINT
    heightINT
    aspect_ratioSTRING