Image Resolution
Stop doing aspect-ratio math in your head
- Width
- Height
Every ComfyUI user has done this: you want a 3:2 image, so you type 1024×683 into an Empty Latent Image node, and then the sampler complains that the dimensions aren't divisible by 8, or the image comes back a weird nonstandard size that upscalers choke on. "Image Resolution" exists so you stop doing that arithmetic in your head - you pick the aspect ratio, it hands back dimensions that actually work.
What it is
NNImageResolution is a resolution calculator. It takes a width, a height, an aspect ratio, and a rounding multiple, and outputs two integers - Width and Height - that are aligned, model-friendly, and (if you want) portrait-oriented. It's a pure number node: no pixels touch it. You wire its outputs into an Empty Latent Image, an empty image, or any size-dependent node. The README's own summary: "Calculates an image resolution based on width, height, aspect ratio, and orientation settings."
How it works
The logic, from the source, handles four cases depending on what you fill in:
- Both width and height given - it preserves your total pixel count and reshapes it to the aspect ratio. Give it 1024×1024 with a 16:9 ratio and it returns ~1365×768, same megapixels, different shape. This is the "maintains target pixel count when changing aspect ratios" feature from the README.
- Width only - height is computed from the aspect ratio (or vice versa).
heightset to -1 (its default) - height just mirrors width, so you get a square starting point.- Neither - falls back to a 1024×1024 pixel budget reshaped to the ratio.
Then comes the model-friendliness part: both dimensions get rounded down to a multiple of divisible_by (default 2; bump to 8 or 16 for latent-friendly sizes), and if portrait is on, the dimensions are swapped so width ≤ height. The result is shown right in the node's UI as text, so you can read what it decided.
The inputs that matter
width- your starting width, 0–8192, default 1024. 0 means "compute from height."height- default -1 (mirror width). 0 means "compute from width."aspect_ratio- the dropdown:auto,1:1,9:7,5:4,4:3,3:2,16:9,2:1,21:9.autoskips reshaping.divisible_by- 2–256, default 2. The alignment multiple.portrait- swap to portrait orientation.
Outputs: Width (INT) and Height (INT). Wire them into anything with size inputs.
When to reach for it
The canonical use is feeding a sampler or latent node the correct size for a given aspect ratio without memorizing resolution charts - pick "16:9" once, get aligned dims forever. It also shines in parameterized workflows: convert the aspect ratio widget to an input and you can swap the whole graph's aspect ratio from a single dropdown, because everything downstream reads the computed Width/Height. That's the plumbing-layer play: one source of truth for a value, fanned out (see the KB's node-plumbing doc on value nodes).
Installing
Ships in bandifiu/ComfyUI-NN-custom-nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/bandifiu/ComfyUI-NN-custom-nodes
Restart ComfyUI (or Manager → "NN-custom-nodes"). Deps: torch, numpy, pillow - no models. GPL-3.0, V3 backend API.
The gotcha that trips people: rounding is down (divisible_by truncation), so your output is always a touch smaller than the raw ratio math - fine for latent nodes, mildly surprising if you're strict about exact pixels. And remember the total-pixel-count behavior: if you enter both width and height expecting it to just align them, it will instead reshape them to the ratio. Want to keep your exact shape? Set aspect_ratio to auto.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| width | INT | 10240–8192 | — |
| height | INT | -1-1–8192 | — |
| aspect_ratio | COMBO | 9 options: auto, 1:1, 9:7, 5:4, 4:3, 3:2, +3 | |
| divisible_by | INT | 22–256 | — |
| portrait | BOOLEAN | false | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| Width | INT | — |
| Height | INT | — |