Aspect Ratio
9 Without Doing Division in Your Head
- ratio_width
- ratio_height
UC_MathAspectRatio does exactly one thing: it takes a width and height and reduces them to their simplest whole-number ratio. Feed it 1920 and 1080 and it hands back 16 and 9. It sounds almost too simple to be useful, and then you're standing in front of a resolution picker trying to remember whether 1344×768 is 16:9 or 21:9 and you're glad it exists.
Why you'd reach for it
Aspect ratio shows up in more places than you'd expect. You might need it for a prompt ("cinematic 2.39:1"), for a video model that wants a ratio instead of raw dimensions, or just to sanity-check that the custom resolution you're about to render is the shape you actually meant. It's also handy in multi-stage pipelines where you want to keep a consistent framing across an img2img chain: confirm the ratio matches, and you know you're not accidentally squishing the composition.
How it works
The mechanism is the ancient greatest-common-divisor trick: the node computes gcd(width, height), then divides both inputs by it. 1920×1080 → gcd is 120 → 16:9. 1024×1024 → gcd 1024 → 1:1. 768×768 → 1:1 too. It can't reduce to non-integer ratios, so a truly odd size like 1234×567 gives you 1234:567 in simplest integer form rather than a decimal - which is exactly what you want from a node whose outputs are integers.
The inputs and outputs that matter
widthandheight- both integers, minimum 1, defaults of 1920 and 1080.- Outputs:
ratio_widthandratio_height- the two reduced integers, ready to feed a prompt builder, a filename, or another math node.
Installing it
It's in ComfyUI-UtilsCollection. ComfyUI Manager → search "ComfyUI-UtilsCollection" → install → restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-UtilsCollection
Restart ComfyUI. The math nodes have no model downloads and the pack's only real deps are opencv-python and typing-extensions.
The one thing worth knowing
Because the outputs are plain integers, you can chain this into a UC_MathDivide or an aspect-ratio comparison downstream - but for most people the real use is simpler: wire your resolution in, read the two numbers, and move on. There's no trap here, which is refreshing in a tool ecosystem that usually has several. If you came from ComfyUI-LogicMath, this is part of the replacement family - accept ComfyUI's swap prompt and uninstall the old pack so the two don't collide.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| width | INT | 1920 | — |
| height | INT | 1080 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| ratio_width | INT | — |
| ratio_height | INT | — |