cacluate width and height
Keep your aspect ratio honest without reaching for a calculator
- w
- h
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
wandhas given - w - keeps
w, derivesh = w / ratio(so9:16gives you a taller height) - h - keeps
h, derivesw = 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(":"), so9:16works and1.5:1also 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.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| w | INT | 5120–10000000 | — |
| h | INT | 5120–10000000 | — |
| lockoff | COMBO | 3 options: false, w, h | |
| rate | STRING | 1:1 | — |
| reverse | COMBO | 2 options: false, true |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| w | INT | — |
| h | INT | — |