Nodes/ComfyUI-SizeFromPresets/Get Similar Resolution Empty Latent
ComfyUI Node

Get Similar Resolution Empty Latent

Match an image's aspect and get the empty latent in one hop

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

The lazy version of GetSimilarResolution - and I mean that as a compliment. Where that node hands you two numbers and makes you assemble the latent yourself, this one takes an image, matches its aspect ratio against the preset list, and hands you the finished empty latent plus the w and h. One node, one wire into the sampler. It's from nkchocoai's ComfyUI-SizeFromPresets and it's the img2img companion the pack is quietly built around.

Why does this matter? When you img2img from a reference photo, your source usually has some arbitrary resolution and aspect ratio - 4032x3024, or whatever your camera spat out. Sampling at that size means leaving the model's trained distribution, which is how you get stretched bodies, doubled limbs, and tiling. This node maps your image's proportions to the nearest trained preset - SDXL's nine ~1MP ratios or SD1.5's five smaller ones - and gives you a latent at a size the model actually likes, keeping the composition's framing intact.

How it works

Same matching logic as its sibling: read the image's w/h, then scan the preset list for the closest aspect ratio:

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

latent = torch.zeros([batch_size, 4, height // 8, width // 8])

The match is by aspect ratio, not resolution. A 4K portrait photo maps to a portrait preset - 832x1216 on the SDXL list - not to a 4K canvas. That's the whole design: match the proportions, render at native budget. If you expected the output size to scale with the input's pixel count, you'll be confused until you read this. It also only looks at the first frame of an image batch.

The inputs that matter

  • image - the reference IMAGE. Its aspect drives the match.
  • is_sdxl - boolean, default true. True = match against the SDXL list, false = SD1.5 list. Set it to match the model you're sampling.
  • batch_size - 1 to 4096, stacked empty latents. Default 1.

Outputs: latent (into the sampler), w, h.

One small note for the SD1.5 path: the 716x403 preset isn't divisible by 8, so the latent floors to a 712x400-decoding canvas while w/h report 716/403. Harmless for most, annoying if you need exact pixels.

Install

ComfyUI Manager, search "ComfyUI-SizeFromPresets", install, restart. Or clone:

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

No requirements.txt, no model downloads - plain Python plus torch. The preset lists load from presets/sdxl.csv / presets/sd15.csv at startup, so edits require a restart, and the code locates those files by the exact folder name ComfyUI-SizeFromPresets - rename the clone and the pack won't load.

CategorySizeFromPresets

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
is_sdxlBOOLEANtrue
batch_sizeINT11–4096

Outputs (3)

NameTypeDescription
latentLATENT
wINT
hINT