Aspect Ratio
9 without mental math
- ratio_width
- ratio_height
Aspect Ratio is the node that does the math you do in your head every time you build a size: feed it a width and a height, and it gives you back the simplified ratio - 1920 and 1080 become 16 and 9. That's the entire job, and it's genuinely useful in a ComfyUI workflow because aspect ratios are everywhere and they're a constant source of subtle bugs.
Why you'd wire this in: matching a generation size to a model's trained aspect ratio is one of the most common quality mistakes in local generation - models train at specific ratios (SDXL's 1152x896, 1216x832, and friends), and generating at a weird ratio wastes resolution or produces awkward crops. If you're writing a "set resolution from a target aspect ratio" workflow, or you want to display/record the ratio of whatever your graph just produced, this node gives you the numbers directly instead of eyeballing them. The two int outputs are handy inputs to string-concatenation nodes for logging or for prompt text like "16:9" built on the fly.
How it works
The mechanism is simple and exact: the node computes the greatest common divisor of width and height (Python's math.gcd) and divides both by it. gcd(1920, 1080) is 120, so you get 16 and 9 - integers, always, even for resolutions that don't reduce cleanly (e.g. 1000x1000 gives 1 and 1). Both inputs are ints with a minimum of 1, so it can't divide by zero, and the outputs are always ints.
Note that it only reduces - it never upscales a ratio. A 1344x768 image gives you 7:4, not something prettier, because that's the honest math. If you want a canonical ratio like 16:9 or 3:2, you'd compare the output against known pairs yourself, or pick a target resolution from a curated list.
The inputs that matter
width(int, min 1) - the first dimension.height(int, min 1) - the second dimension.
Outputs are two ints: ratio_width and ratio_height, e.g. 16 and 9.
Install
This node ships in the ComfyUI-LogicMath pack. Install via ComfyUI Manager (search "ComfyUI-LogicMath", Install, restart) or:
cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-LogicMath
No pip dependencies, no model files. The pack targets ComfyUI's newer extension API, so update ComfyUI if the node doesn't show up.
Common issues
- "The ratio looks wrong" - the node only reduces; a resolution that isn't a clean multiple of a common pair returns whatever the honest ratio is. That's correct behavior.
- The output ints are huge and shared - check whether you actually wired width and height, or left one at its default of 1920x1080.
This is a small node with a small job, but it's one of those that stops you from guessing - and in a graph where dimensions flow around as variables, "don't guess the ratio, compute it" is good hygiene.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| width | INT | 1920 | — |
| height | INT | 1080 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| ratio_width | INT | — |
| ratio_height | INT | — |