Aspect Ratio From Size ๐
Get the ratio string from a width and height
- aspect_ratio
You have a width and a height. You need the aspect ratio as a tidy string like 16:9 or 3:2 - because some downstream node wants it in that form. AspectRatioFromSize does that one conversion. Feed it two numbers, get back the simplified ratio. It's the least glamorous node in the pack and one of the handier ones once you need it.
Part of ComfyUI-MieNodes (ComfyUI_MieNodes), MieMieeeee's utility pack, in the Common group.
Why you'd use it
Plenty of nodes and models take an aspect ratio as a string rather than as raw dimensions. The pack's own Ideogram4PromptGenerator, for instance, has an aspect_ratio string input - and Ideogram 4 is happy to render anything from square to ultra-wide, so you want to hand it the right ratio. Rather than eyeballing that "1216x832 is roughly 3:2" in your head (and getting it slightly wrong), you compute it.
The typical wiring is: take the width and height you're already using elsewhere in the graph - from a latent, an image, or your own primitives - run them through this node, and pipe the resulting aspect_ratio string into whatever field wants it. It keeps your ratio honest and in sync with your actual dimensions, so when you change the size, the ratio string updates with it instead of going stale.
The inputs and outputs that matter
Two required inputs:
width(INT, default 1024) - the pixel width.height(INT, default 1024) - the pixel height.
One output:
aspect_ratio(STRING) - the simplified ratio, e.g.1:1for 1024x1024. Wire it into any node that takes an aspect-ratio string.
That's the whole thing. No formats to choose, no mode switches.
Installing it
ComfyUI Manager โ search ComfyUI-MieNodes โ install โ restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/MieMieeeee/ComfyUI-MieNodes
then restart. No model download. Nodes appear under the ๐ MieNodes menu.
Common issues
Odd sizes give odd ratios. The node simplifies the ratio from the exact width and height. If your dimensions don't reduce to a clean common ratio - say 1000x812 - you'll get whatever that actually simplifies to, not a friendly 3:2. If you need standard ratios, feed it standard dimensions.
It reads dimensions, it doesn't set them. This computes a ratio from a size; it doesn't resize anything or produce a width/height. If you want to go the other way (pick a ratio, get dimensions), that's a different kind of node.
Match it to a consumer that wants a string. The output is text like 16:9. If your target node wants separate width/height integers instead, this isn't the adapter you need - it's specifically for the string-ratio case.
Wiring it live. The nice part is that it stays in sync automatically: pull the width and height straight off your latent or image rather than typing them twice, and the ratio updates whenever you change the size. That's the difference between a ratio that's always correct and one you forgot to update three tweaks ago. No model download, no settings, no surprises - it's a two-number-in, one-string-out helper you drop in once and forget about.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| width | INT | 10241โ16384 | Image width in pixels. |
| height | INT | 10241โ16384 | Image height in pixels. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| aspect_ratio | STRING | โ |