Nodes/zsq_prompt/Image Ratio
ComfyUI Node

Image Ratio

9

By windfancy·Created 2 years ago·Updated 5 months ago· 2
Image Ratio
  • image
  • width_ratio_int
  • height_ratio_int
  • width_ratio_float
  • height_ratio_float

Aspect ratio is the sort of thing you usually just eyeball - until you're building a workflow that needs to know it. imageRatio measures an image and returns its aspect ratio as reduced integers: feed it a 1344×768 image and it tells you 16:9. It's a measurement node, not a transformation - it doesn't crop or resize anything. It just answers the question "what shape is this?" so the rest of your graph can react.

How it works

The mechanism is a greatest-common-divisor reduction, the same math behind "16:9" as a fraction. It takes the image's width and height, computes their GCD, and divides both by it. 1024×576 becomes 16:9, 768×512 becomes 3:2, 1024×1024 becomes 1:1. Nothing gets resampled or touched; the image passes through untouched on the way to its own dimensions being reported.

The inputs and outputs

One input: image. Four outputs, and here's where it gets a little silly - you get width_ratio_int and height_ratio_int, plus width_ratio_float and height_ratio_float. But look at the source: the float outputs are the same values as the int ones. The "float" ratio is not a decimal like 1.78; it's the same 16 and 9, just in a FLOAT-typed port. So pick whichever output type your downstream node wants and don't expect a third thing from the "float" pair.

Where it earns its keep

The ratios are most useful when they're enforced: feed the int outputs into a node that sets image dimensions, or compare them to a target ratio to decide whether to crop or pad. It's also a neat companion to this pack's imageSize (raw pixel dimensions) and checkpoint_sampler (resolution presets) - you can read an existing image's shape and tell a downstream generation step to match it.

Installing it

Part of windfancy/zsq_prompt - search "zsq_prompt" in ComfyUI Manager and install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/windfancy/zsq_prompt

then restart. Note the pack drags in heavy requirements (transformers, ultralytics, onnx) that this node never touches. If Manager flags a "conflict" for zsq_prompt, it's the pack's generic class names colliding in the manager's index - the community's advice is to ignore it unless you actually run the other pack too.

Verdict

A tiny utility with one job and one quirk (identical int/float outputs). Install it as part of the pack, use it when a workflow needs to know its own shape.

CategoryZSQ/Image

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (4)

NameTypeDescription
width_ratio_intINT
height_ratio_intINT
width_ratio_floatFLOAT
height_ratio_floatFLOAT