Nodes/ymc-node-suite-comfyui/cacluate width and height
ComfyUI Node

cacluate width and height

Keep your aspect ratio honest without reaching for a calculator

By YMC-GitHub·Created 3 years ago·Updated about a year ago· 20
cacluate width and height
    • w
    • h
    w512
    h512
    lockoff
    rate1:1
    reverse

    Aspect-ratio math is the most boring arithmetic in ComfyUI, and also the most repeated: you know you want a 9:16 portrait at 768 wide, so what's the height? Cacluate width and height (yes, "cacluate" - the typo is in the node's own display name, just search "cacluate" if you can't find it) answers that in the graph instead of in your head. Give it one dimension, a ratio, and a lock, and it returns both dimensions as INTs ready for an EmptyLatentImage.

    It's the kind of utility you reach for when you're swapping between ratios a lot. Instead of retyping 512x768 by hand for every checkpoint or crop test, you type 9:16, lock the width, and the height follows - and reverse flips the result in one click.

    How it works

    You give it a starting w and h, then pick what to lock with lockoff:

    • false - no ratio math at all; returns w and h as given
    • w - keeps w, derives h = w / ratio (so 9:16 gives you a taller height)
    • h - keeps h, derives w = h * ratio

    The rate string is parsed as width:height (default 1:1), and reverse (default false) swaps the outputs - handy when you modeled the ratio one way but want the other orientation. Everything is truncated to INT at the end, so you get clean, sampler-friendly values rather than 512.888 pixels.

    Inputs and outputs

    • w, h - INT starting values, default 512 each
    • lockoff - false | w | h
    • rate - STRING, "1:1" default, e.g. "9:16", "2:3"
    • reverse - false | true
    • Outputs: w and h as INTs

    Installing it

    # ComfyUI Manager: search "ymc suite" and install ymc-node-suite-comfyui
    # or:
    cd ComfyUI/custom_nodes
    git clone https://github.com/YMC-GitHub/ymc-node-suite-comfyui
    

    Restart after installing. Four tiny pure-Python PyPI helpers self-install; no models, no GPU cost.

    Gotchas

    • It's classified under ymc suite/text/plain, which confuses everyone - there's nothing text-y about it. Search "cacluate" or browse the ymc suite menu.
    • The ratio is parsed with a naive split(":"), so 9:16 works and 1.5:1 also works, but give it exactly two parts or the math silently misbehaves.
    • INT truncation means a computed height like 853.3 becomes 853. That's fine for latents (8 is the only alignment ComfyUI really cares about), but if you need exact multiples of 8, round up in your head before you wire it in.
    • Not a workflow-critical node to fear: nothing here loads models or touches the sampler. Worst failure mode is a wrong-looking number, which is why it pairs naturally with a show text node for eyeballing.
    Categoryymc suite/text/plain

    Inputs (5)

    NameTypeDefaultDescription
    wINT5120–10000000
    hINT5120–10000000
    lockoffCOMBO3 options: false, w, h
    rateSTRING1:1
    reverseCOMBO2 options: false, true

    Outputs (2)

    NameTypeDescription
    wINT
    hINT