ComfyUI Node

AspectRatioToSize

9 at 1920' math so you don't have to

By sugarkwork·Created 2 years ago·Updated 2 months ago· 3
AspectRatioToSize
    • Size
    aspect_ratio16:9
    resolution1920

    Do the ratio math once, then stop

    There's a version of this conversation in every ComfyUI server: "I want 16:9 with a 1920 long side - so width is 1920 and height is… 1920 ÷ 16 × 9 = 1080." Fine once. Not so fine the tenth time, or when the ratio is 21:9, or when you're switching between portrait and landscape and keep typing the short side into the wrong box.

    AspectRatioToSize exists for exactly that. You give it an aspect ratio and one number - the long side - and it hands back a Size object holding the width and height. That's the whole job, and it does it without models, without dependencies, and without touching your GPU.

    What it actually computes

    The mechanism is dead simple, about ten lines in the pack's nodes.py:

    • The resolution you pass is treated as the longer side and snapped to the nearest multiple of 64.
    • The other side is int(long_side ÷ larger_ratio × smaller_ratio).

    So 16:9 + 19201920×1080, and 9:16 + 19201080×1920. The long-side constraint is the clever bit: you never have to figure out which dimension gets the 1920, because the node decides based on whether the ratio is landscape or portrait. It even accepts decimal ratios - the repo's tests show 1:0.5625 resolving to 1920×1080 - so anything that reduces to a number works.

    Inputs and outputs that matter

    Only two inputs, and one of them is the whole game:

    • aspect_ratio - a "W:H" string like "16:9". Keep the colon. The node splits on it, and a malformed value like 169 will throw an error.
    • resolution - the long side in pixels. Default 1920, range 128–8192, step 64.

    The single output is a Size object (type SIZE). And here's the thing beginners trip on: that object can't go straight into Empty Latent. Empty Latent wants plain integers. The Size type is this pack's own little datatype, so you chain it into the sibling SizeToWidthHeight node, which unpacks it into Width, Height, LargeSide, and SmallSide ints you can wire anywhere.

    One honest gotcha

    Only the long side gets snapped to a multiple of 64; the short side is just int(). For the common cases that's harmless - 16:9 at 1920 gives 1080, which VAEs decode fine. But 1080 is not a multiple of 64, and Flux models want latents divisible by 64. If Flux rejects your Size, round the short side up to the next 64 yourself, or reach for the pack's CalcFactorWidthHeight with divide=64 and let it snap both dimensions.

    Install

    It's one of the easy ones - no model downloads, and the pack's pyproject.toml declares zero dependencies (it only imports torch and PIL, both already inside ComfyUI).

    Via ComfyUI Manager: search for "AspectRatioToSize" and click Install.

    Or manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/sugarkwork/ComfyUI_AspectRatioToSize
    

    Restart ComfyUI. That's it - no pip install, no weights to fetch. It's a small pack from a solo Japanese dev, published to the Comfy Registry and shipped with unit tests, so the "clone a random repo and run it" risk is about as low as it gets for a custom node. Your workflow gets a Size output, a sibling node to unwrap it, and no more math in your head.

    Categoryimage

    Inputs (2)

    NameTypeDefaultDescription
    aspect_ratioSTRING16:9
    resolutionINT1920128–8192

    Outputs (1)

    NameTypeDescription
    SizeSIZE