Image Aspect Ratio Extractor
Know the exact ratio you're working with — or the ratio you'd get after cropping
- image
- aspect_ratio
Image Aspect Ratio Extractor is the "what shape am I actually dealing with?" node. Feed it an image and it hands you the aspect ratio as a string - either the nearest familiar one like 16:9, or the exact reduced fraction like 65:128. If you've ever stared at a workflow and realized you didn't actually know whether that input was portrait-ish or square-ish, this is the node that settles it.
It matters more than it sounds. Every model family has a native shape - SDXL was trained on a small set of ratios around 1:1, Flux is happy at 1024×1024 and up, and your social-media template demands exactly 4:5 or 9:16. If you're adapting assets to a target ratio (padding, not just cropping), you need to know the starting point first. That's the gap this fills.
How it works
Inputs are the image, a ratio_type, and four crop inputs: top_crop, bottom_crop, left_crop, right_crop (0–99 each).
The ratio_type decides the output format:
round tosnaps to the nearest common ratio: 1:4, 1:2, 3:4, 1:1, 4:3, 3:2, 16:9, 2:1, or 4:1. Great for "tell me in words I can match a template to."aspect ratioreduces the exact width/height with a greatest-common-divisor - so a 1536×1024 image reports as3:2, warts and all.
The clever part is the crop inputs. They let you simulate "if I cropped this much off each side, what ratio would be left?" before you commit to the crop. The node computes the cropped dimensions, then the ratio from those. So if you're about to crop a 4:3 image to a square for a thumbnail, you can check that a certain crop setting actually lands on 1:1 rather than guessing and re-cropping twice.
One limit is baked into the design: ratios are clamped to the 0.25–4.0 range (1:4 to 4:1). A 21:9 ultrawide will report 4:1, not 2.33:1 - it caps out, by design, and the code logs a warning when it clamps. Worth remembering if you ever feed it a pano and wonder where your ratio went.
The real caveat
The output is a STRING. That means it's for your eyes, text widgets, and logging - you can't wire it into numeric math the way you'd feed an INT into a resize node. If you want the ratio as a number to compute with, divide width by height using the pack's resolution extractor instead. This node is the human-facing version; that one is the machine-facing version. They sit side by side in the pack for exactly that split.
Install
Same as the rest of the pack: ComfyUI Manager (search "ComfyUI-Image-Resizing"), or:
cd ComfyUI/custom_nodes
git clone https://github.com/Zar4X/ComfyUI-Image-Resizing
Restart and it lives under Image Resizing/Extract. No models, no downloads, nothing heavy. It's a niche utility - but "what ratio am I actually at, and what would a crop get me?" is a question you'll be glad to have answered in one node.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| ratio_type | COMBO | round to | 2 options: round to, aspect ratio |
| top_crop | INT | 00–99 | — |
| bottom_crop | INT | 00–99 | — |
| left_crop | INT | 00–99 | — |
| right_crop | INT | 00–99 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| aspect_ratio | STRING | — |