Nodes/ComfyUI_yanc/๐Ÿ˜ผ> Resolution by Aspect Ratio
ComfyUI Node

๐Ÿ˜ผ> Resolution by Aspect Ratio

Stop guessing dimensions, let the model's training ratios do it

By ALatentPlaceยทCreated 2 years agoยทUpdated 2 years agoยท 80
๐Ÿ˜ผ> Resolution by Aspect Ratio
  • image
  • width
  • height
โ—„stable_diffusionโ–พโ–บ

SD 1.5 and SDXL weren't trained on arbitrary image sizes - they were trained on a handful of specific resolutions per aspect ratio, and generating outside that set is one of the most common causes of the classic "stretched body, doubled head" artifact. Most people either memorize the resolution table or eyeball it. This node does the lookup for you: hand it an image (for its aspect ratio) and tell it which architecture you're targeting, and it hands back the closest matching trained resolution.

That's genuinely useful earlier in a workflow than you'd think. It's not really an "output resolution" node - it's a "figure out what resolution to generate at" node, usually feeding the width/height of an Empty Latent Image at the very start of a graph, driven off a reference photo you loaded to match its proportions.

How it works

The node reads the width and height of the image you feed it, works out the aspect ratio, and matches it against the known set of trained resolutions for whichever architecture you pick. For SDXL specifically, that trained set is documented and small - 1024ร—1024, 1152ร—896, 1216ร—832, 1344ร—768, 1536ร—640 (and their rotations) - so a portrait reference photo maps to something like 896ร—1152, not to whatever raw pixel dimensions the photo happened to be. For SD 1.5 the native training resolution is lower (512ร—512-class), and the node scales its matching down accordingly.

The inputs and outputs that matter

  • stable_diffusion - a two-choice switch: 1.5 or SDXL. This picks which architecture's resolution table the node matches against, so set it to whatever model you're actually about to sample with - picking the wrong one gets you a resolution that's technically valid for the other architecture and off-native for yours.
  • image - any IMAGE. Its content doesn't matter, only its aspect ratio does. A common pattern is loading a reference photo purely to borrow its proportions.

Outputs are width and height (both INT) - wire them straight into an Empty Latent Image, or into anything else that wants explicit dimensions.

How to install it

Via ComfyUI Manager: search "yanc" or "YANC - Yet Another Node Collection," install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/ALatentPlace/ComfyUI_yanc

then restart. No model downloads, no extra dependencies - it's pure arithmetic on the image tensor's shape.

Common issues & troubleshooting

The output doesn't match your source image's exact aspect ratio. That's by design, not a bug - the whole point is snapping to the nearest trained ratio rather than preserving your input's exact proportions, because generating at an untrained ratio is what causes the artifacts in the first place. If you need the exact original aspect ratio preserved, this node isn't the right tool; crop or letterbox your reference to one of the trained ratios first.

You picked SDXL but you're running an SD 1.5 checkpoint (or vice versa). The node has no way to know which checkpoint you've actually loaded elsewhere in the graph - the stable_diffusion choice is manual. Generating SDXL-native resolutions through an SD 1.5 model (or the reverse) reintroduces the exact artifacts this node exists to avoid, so keep it in sync with your actual model choice by hand.

You're on Flux, Illustrious, or something newer. The two-choice list here is SD 1.5 and SDXL only - newer architectures have looser resolution constraints (Flux just wants dimensions divisible by 64 within a flexible range) and aren't what this node targets. Treat its output as a good starting point rather than gospel if you're on something outside those two.

CategoryYANC/๐Ÿ˜ผ Image

Inputs (2)

NameTypeDefaultDescription
stable_diffusionCOMBO2 options: 1.5, SDXL
imageIMAGEโ€”

Outputs (2)

NameTypeDescription
widthINTโ€”
heightINTโ€”