Nodes/Prompt & Dimensions from LLM/Dimensions from Ratio
ComfyUI Node

Dimensions from Ratio

Feed It '16:9', Get a Latent Size Back

By BleynChannel·Created 13 days ago·Updated 3 days ago· 3
Dimensions from Ratio
  • images
  • width
  • height
◄wh_ratio—►
◄ratio_follow—►
◄megapixels1.0►
◄multiple8►

Here's the fun part: this node ships in a pack named after Qwen's prompt-enhancer model, and it has absolutely nothing to do with Qwen. No checkpoint, no LLM, no download. It's a calculator with two outputs.

It does one job: give it an aspect ratio (or an image you already have) and it hands you a width and height to wire into a latent or a generation node. If you've ever typed 1368 into an Empty Latent Image, guessed at 1920x1080, and gotten a stretched face for your trouble, this is the node for you.

Why you'd actually want it

Two things about 2026 models matter here. First, the old SDXL discrete-ratio table (1024x1024, 1152x896, 1344x768…) has mostly loosened - most current models take any resolution inside a megapixel band, so "how many megapixels" is now a real per-model decision. Z-Image and Flux 2 Klein are happy at 1–2 MP and degrade past that. Second, an enormous number of workflows want the output to match the shape of an input: refine passes, img2img chains, video first frames. People build whole packs for this. Dimensions from Ratio is the small, boring version of that, which is what you want in a plumbing node.

How it works

Pick one of two mutually exclusive paths.

wh_ratio + megapixels. Write an aspect ratio like 16:9, 3:2, 21:9, even 2.35:1 - the parser wants a colon and two numbers, nothing more. The math is deliberately copied from ComfyUI's own built-in Resolution Selector: the pixel budget is megapixels × 1024 × 1024 (so 1 MP literally means 1024²), then each side is sqrt(area / (w × h)) scaled out and rounded to the nearest multiple of multiple. Concretely: 1:1 @ 1 MP → 1024 × 1024, 16:9 @ 1 MP → 1368 × 768.

ratio_follow. Write <image1> and the node copies the exact pixel size of the reference image you attached - megapixels and multiple are ignored entirely on this path. This is the "make the latent the same size as my last output" mode.

Both fields filled in? ratio_follow wins. That's deliberate, not a bug.

The inputs that matter

Only five inputs, and a beginner really only touches two. wh_ratio and ratio_follow are the switch; leave one blank. megapixels (0.1–16.0, default 1.0) is your size budget - for most 2026 models stay in the 1–2 range. multiple (8–128, step 4, default 8) is the grid it rounds to; 8 keeps the VAE happy, bump it to 64 if you're staying on the SDXL lineage, and some video models want 32 or 64.

images is the autogrow input: up to ten reference images, keyed from image0 up. Here's the trap. ratio_follow is written one-based, so <image1> means the first image you attached - the image0 socket. Any other spelling is rejected: image1, <1> and 1 all throw, and the error reads as cryptic until you know why.

Outputs are width and height, both INT, and both meant to be wired. Right-click Empty Latent Image's width widget → Convert widget to input, repeat for height, connect. (No prompt output here - that belongs to the pack's sibling node, the one that parses the Qwen prompt-enhancer JSON.)

Installing it

No dependencies - the whole thing is Python's json, math and re. No requirements.txt to blow up, and no weights to download: the Qwen models the README links belong to the pack's other node, not this one.

cd ComfyUI/custom_nodes
git clone https://github.com/BleynChannel/ComfyUI-QwenImage-PromptExtractor.git

Restart ComfyUI and look under prompt/resolve. ComfyUI Manager works too - the pack is on the registry (publisher bleyn), listed as "Prompt & Dimensions from LLM". One caveat: this is a V3-schema pack (from comfy_api.latest import io) whose pyproject.toml declares requires-comfyui >= 0.3.40. On an older ComfyUI the node just won't appear. Grep the source for NODE_CLASS_MAPPINGS, find none, and don't panic - that's the new authoring API, not a broken install.

Where people get burned

The errors here are unusually good, so read them. Forgetting both ratios gives you “Provide either 'wh_ratio' (e.g. '16:9') or 'ratio_follow' (e.g. '<image1>') to determine the image dimensions.” Using a slash instead of a colon gives you a message telling you so - 16/9 does not parse. Naming an image you never attached gets you the list of images it did receive.

The other thing to know: the in-node tooltip says sizes are “rounded up to” the grid, but the code rounds to the nearest multiple. Trust the README and the behaviour, not the tooltip - at multiple = 64 that's a difference of up to 32px per side.

And if you only ever generate 1:1 and 16:9, the core Resolution Selector already does this and it's one less pack on your disk. What earns this node its spot is arbitrary ratios the core dropdown doesn't list, and ratio_follow, which the core node can't do at all.

Categoryprompt/resolve

Inputs (5)

NameTypeDefaultDescription
wh_ratioSTRINGAspect ratio e.g. '16:9'. Used with megapixels to derive a resolution. Mutually exclusive with ratio_follow.
ratio_followSTRINGReference an uploaded image's exact size, e.g. '<image1>'. Mutually exclusive with wh_ratio.
megapixelsFLOAT1.00.1–16Target size in megapixels (0.1-16.0). Used only when wh_ratio is provided; ignored when ratio_follow is used.
multipleINT88–128Pixel grid that resolved width/height are rounded to (default 8). Only used when wh_ratio is provided.
imagesCOMFY_AUTOGROW_V3Up to 10 reference images. ratio_follow can name one of them (e.g. '<image1>') to reuse its exact size.

Outputs (2)

NameTypeDescription
widthINT—
heightINT—