Nodes/ComfyUI-SizeFromPresets/Get Similar Resolution
ComfyUI Node

Get Similar Resolution

Hand it any image, get back the closest trained size

By nkchocoai·Created 3 years ago·Updated about a year ago· 13
Get Similar Resolution
  • image
  • w
  • h
is_sdxltrue

Here's the node from this pack that earns its place in img2img workflows. Feed it any image and it returns w and h - the size of the preset that best matches your image's aspect ratio. Wire those into an Empty Latent Image (or a resize step) and your source image's composition gets re-framed at a resolution your model was actually trained on. It's from nkchocoai's ComfyUI-SizeFromPresets, and it's the closest the pack gets to a "smart" node.

The motivation is the same as the rest of the pack: models generate cleanly at their native pixel budget on their trained aspect ratios, and anything else invites stretched anatomy, doubled limbs, or tiling. SDXL lives at ~1MP across nine ratios; SD1.5 lives at ~512 across five. This node's job is to look at your image and tell you which of those boxes it fits best.

How it works - and the one thing people get wrong

The matching is on aspect ratio, not pixel count. The code reads the image's width/height, computes w / h, then scans the presets for the one whose aspect ratio is closest:

for w, h, aspect in size_presets:
    if abs(aspect - aspect_src) < abs(similar_aspect - aspect_src):
        similar_aspect, similar_res_w, similar_res_h = aspect, w, h

So a 4K landscape image doesn't map to a "4K-sized" preset - there isn't one. It maps to the landscape preset whose proportions are nearest, at the model's native resolution. A 3840x2160 photo (16:9) matches 1344x768 on the SDXL list, not something bigger. If you were expecting resolution matching, that's the trap; it's aspect matching, which is usually exactly what you want for staying in the training distribution.

It only looks at the first frame, too - feed it a video or an image batch and it sizes off image[0] alone.

The inputs that matter

  • image - any IMAGE tensor. Its aspect ratio drives the match.
  • is_sdxl - a boolean, default true. True matches against the SDXL preset list; false switches to the SD1.5 list. Flip this to match whatever model you're actually sampling with.

Outputs: w and h INTs. There's a sibling node, GetSimilarResolutionEmptyLatent, that builds the latent for you - grab that one if you don't want to hand-assemble the pipeline.

A real workflow for it

The classic use: img2img from a reference photo. Load your image, feed it here, feed w/h into an Empty Latent Image, then sample with your img2img settings at that latent's resolution. Your output keeps the source's framing but renders at a clean, trained size instead of whatever oddball dimensions the original had.

Install

Via ComfyUI Manager, search "ComfyUI-SizeFromPresets". Or clone:

cd <ComfyUI>/custom_nodes
git clone https://github.com/nkchocoai/ComfyUI-SizeFromPresets.git

Restart after installing. No requirements.txt, no models, no dependencies beyond what ComfyUI ships - the node is plain Python plus torch. Found under the SizeFromPresets category. If you want to tune which sizes count as "similar," edit presets/sdxl.csv or presets/sd15.csv and restart; the lists load at import. Don't rename the clone folder, or the CSV lookup fails and the whole pack won't load.

CategorySizeFromPresets

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
is_sdxlBOOLEANtrue

Outputs (2)

NameTypeDescription
wINT
hINT