🧩 MUTOU | Smart Aspect Ratio
Don't guess your image's dimensions — let this node read them for you
- image
- width_int
- height_int
- ratio_name
- width_text
- height_text
- wh_text
What it is
MUTOU Smart Aspect Ratio is one of those little utility nodes you don't appreciate until you need it. Feed it any image and it reads the real width and height straight off the tensor, works out the actual aspect ratio, and tells you which entry in your list - 1:1, 16:9, 21:9, whatever you set - comes closest. Then it hands you the original dimensions back, both as integers and as strings.
The name is grander than the ~50-line single-file reality, but the important thing is what it doesn't do. It does not resize, crop, or regenerate a single pixel. The README hammers this twice for a reason: this is a measurement and logic node, not an image transform. If you're building img2img, API, or batch workflows where the incoming image could be any shape, that's exactly what you want - models are trained at native resolutions and a random web image almost never is, so having the real numbers available for conditional logic beats hardcoding a guess.
How the matching works
The mechanism is simple enough to trust. ComfyUI stores images as [Batch, Height, Width, Channel] tensors, so the node reads height from slot 1 and width from slot 2 - no decoding, no round-trip through PIL, just shape introspection. It computes width / height, parses your ratio_list into numeric ratios, and picks the entry with the smallest absolute difference. Because it always uses w/h, a portrait image listed as 9:16 (0.5625) matches portrait input correctly - both orientations are handled as long as you list them.
Worth knowing: the parser is tolerant. It accepts commas, newlines, full-width Chinese commas, even full-width colons. But an entry without a colon gets skipped silently, and if nothing parses at all, ratio_name falls back to "Original".
The inputs and outputs that matter
Only two inputs, both required:
image- any IMAGE tensor.ratio_list- a multiline STRING widget, default1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 21:9. Add cinematic ones like1.85:1or2.39:1if you work in film.
Six outputs, three pairs that matter:
width_int/height_int- the original dimensions as INT, for feeding real logic (like setting upscale targets).ratio_name- the matched ratio text, e.g."16:9".width_text/height_text/wh_text- string versions,wh_textbeing e.g."1024x768". Wire these into any text-display or string-logic node.
Installing it
ComfyUI Manager can find it by searching "MUTOU Smart Aspect Ratio", or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/c1660181647-hash/ComfyUI_MUTOU_SmartAspectRatio.git
Then restart ComfyUI. There's no requirements.txt, no model downloads, no weights to hunt down - it only needs torch, which ComfyUI already ships. MIT-licensed, one file, done.
Where people get tripped up
The biggest trap is assuming "aspect ratio" means "resize." It doesn't - if you expected your landscape image to come out letterboxed or cropped, you've got the wrong tool. Use it to read the truth, then wire width_int/height_int into an actual upscaler or resolution node.
Second: keep the ratio_list tidy. It's a single text widget, so separate entries with commas or newlines and don't leave stray characters - a bad entry just gets dropped, which makes the match subtly worse rather than erroring out. And remember it outputs the original dimensions even if your upstream loader already resized, so put it after the resize point if you want post-resize numbers. For a small node that does one thing cleanly, that's a decent deal.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| ratio_list | STRING | 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 21:9 | — |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| width_int | INT | — |
| height_int | INT | — |
| ratio_name | STRING | — |
| width_text | STRING | — |
| height_text | STRING | — |
| wh_text | STRING | — |