Nodes/ComfyUI-Image-Resizing/Image Aspect Ratio Extractor
ComfyUI Node

Image Aspect Ratio Extractor

Know the exact ratio you're working with — or the ratio you'd get after cropping

By Zar4X·Created about a year ago·Updated 14 days ago· 5
Image Aspect Ratio Extractor
  • image
  • aspect_ratio
ratio_typeround to
top_crop0
bottom_crop0
left_crop0
right_crop0

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 to snaps 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 ratio reduces the exact width/height with a greatest-common-divisor - so a 1536×1024 image reports as 3: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.

CategoryImage Resizing/Extract

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
ratio_typeCOMBOround to2 options: round to, aspect ratio
top_cropINT00–99
bottom_cropINT00–99
left_cropINT00–99
right_cropINT00–99

Outputs (1)

NameTypeDescription
aspect_ratioSTRING