Nodes/ComfyUI-988/Ratio Calculator 988
ComfyUI Node

Ratio Calculator 988

Read an image's aspect ratio so you don't guess it

By kajan988·Created 3 months ago·Updated about a month ago· 1
Ratio Calculator 988
  • image
  • ratio

The single most common way to ruin an image-to-image run is feeding a model a canvas shape it wasn't asked for - you've got a 4:3 source, and without checking you generate at 16:9 and the model dutifully stretches the composition. Ratio Calculator 988 is the two-second check that prevents that: feed it an image, and it tells you the closest standard aspect-ratio label (16:9, 4:3, 3:2, …) by comparing the image's actual width/height against a table of common ratios.

It's a tiny node - one input, one output - but it's the "measure" half of the ratio workflow that matters more than people expect. In SDXL/Flux land, aspect ratio is a first-class concern: these models were trained at specific canvas shapes, and the KB's guidance is that you should pick a canvas close to what the model likes rather than fight it.

How it works

It reduces the image's dimensions by their greatest common divisor to get the true ratio, then finds the entry in its ratio table whose ratio is closest in difference. The closest label wins - so a 1920×1080 image reports 16:9, and a 1024×1024 image reports 1:1. Simple, deterministic, and it does it in milliseconds.

Inputs and outputs

  • image - any IMAGE tensor (an input image, an output from a loader, a processed result).
  • ratio (output) - the closest aspect-ratio label as a string. Note it's typed * (ANY), so you can wire it into another node that accepts a string - most usefully into a ratio-selection input like Ratio to Size 988's ratio dropdown, or just to Display UI 988 to read it.

It's also an output node, so the label renders on the graph - you don't even need a display node if all you want is the answer.

Why you'd reach for it

Two workflows, mainly. First: img2img or image-to-video where you want the output to match the source's shape - measure first, generate second, no more "why did it stretch" surprises. Second: chained into a size planner, where you read a reference image's ratio and hand it straight to Ratio to Size 988 to compute a clean, model-friendly dimension for a new generation. That pairing (measure → size → generate) is a tidy, genuinely reusable pattern.

Gotchas

  • It returns the closest label, not an exact ratio. A 1.35:1 source will report 4:3, which is usually what you want - but if you need the exact ratio, this isn't the node; it's the "nearest bucket" node.
  • The output is a display string, not a tuple of numbers. Wire it where a string (or ANY) is accepted; don't expect width/height ints out of it.

Install

Part of ComfyUI-988: Manager (search "ComfyUI-988") or:

cd ComfyUI/custom_nodes
git clone https://github.com/kajan988/ComfyUI-988
cd ComfyUI-988
pip install -r requirements.txt

Then restart. It's pure math on the image shape - no models, no downloads.

Category🦇988/Image

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (1)

NameTypeDescription
ratio*Closest aspect-ratio label string