ComfyUI Node

Aspect Ratio

Go from '16:9' to actual pixels

By ShinChven·Created about a year ago·Updated 7 months ago· 3
Aspect Ratio
    • target width
    • target height
    • longest side
    • formatted
    aspect_width16
    aspect_height9
    longest_side1024

    Sometimes you know the shape you want before you know the pixels - "16:9, landscape, don't go past 1024 on the long side" - and typing that out as exact width/height numbers is annoying enough that you'd rather a node just do it. That's the entire job here: feed it a ratio and a cap, get back the pixels.

    How it works

    You give it a ratio as two integers - aspect_width to aspect_height - plus a longest_side cap, and it works out the actual width and height that satisfy that ratio without the longer edge going past your cap. 16:9 at a longest side of 1024 comes out to 1024×576. Swap which number is bigger and you flip landscape to portrait. It's the ratio-first sibling to this pack's Width & Height node - same family, opposite starting point: one starts from pixels and scales, this one starts from a shape and fills in the pixels.

    The inputs and outputs that matter

    • aspect_width, aspect_height (INT, default 16 / 9) - your ratio, as two whole numbers, not a decimal. Ultrawide is something like 21:9; portrait just means the height number is bigger than the width one.
    • longest_side (INT, default 1024, range 8–16384, step 8) - the ceiling on whichever side ends up longer.

    Outputs: target width / target height are the computed pixel size - wire these into Empty Latent Image or a resize node. longest side passes your setting straight through, and formatted is a string version, probably for a label rather than for further math.

    Where this actually matters

    Getting the ratio math right is the easy part; picking a ratio your model was actually trained on is the part people get wrong. Every checkpoint has a native resolution, and pushing far off it is a well-known way to get duplicated limbs or a warped-looking result - it's common enough that "you're using a model trained on 1024×1024 trying to make ridiculously different aspect ratios" is basically a stock reply on the SD subreddits. SDXL's trained ratios cluster around things like 1152×896, 1216×832, 1344×768, and 1536×640 - 16:9 isn't actually one of them. If you're on SDXL and want a 16:9 result, you'll get a cleaner generation aiming this node at something closer to 7:4 and cropping afterward than asking it for 16:9 directly. Flux is more tolerant of odd ratios but still wants both sides divisible by 64. This node will happily compute any ratio you throw at it - it has no idea what your model was trained on, so that judgment call is still yours.

    How to install it

    Same pack as Width & Height and Rescale Node, so one install gets all three. Via ComfyUI Manager: search "ShinChven's Custom Nodes Package". By hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/ShinChven/sc-comfy-nodes
    

    Restart ComfyUI. No dependencies beyond Python itself, no models to fetch.

    Common issues & troubleshooting

    A shared workflow flags this node as missing. "Aspect Ratio" is a genuinely common node name - several bigger packs have their own version - so confirm ComfyUI Manager resolved it to ShinChven's pack specifically and not a similarly-named node from something you don't have installed.

    Output looks broken at an extreme ratio. The node doesn't sanity-check your input - ask for 40:1 and it'll give you 40:1, and that's going to look bad on basically any model regardless of the arithmetic being correct.

    Not finding help online. This is a small, low-traffic pack from one developer - there's no active thread or troubleshooting post to lean on for it. A GitHub issue is the realistic path if something's genuinely broken, not a forum search.

    CategoryImage Dimensions

    Inputs (3)

    NameTypeDefaultDescription
    aspect_widthINT161–16384
    aspect_heightINT91–16384
    longest_sideINT10248–16384

    Outputs (4)

    NameTypeDescription
    target widthINT
    target heightINT
    longest sideINT
    formattedSTRING