Nodes/ComfyUI-GlifNodes/Image to SDXL compatible WH
ComfyUI Node

Image to SDXL compatible WH

Get your image into an SDXL-native resolution without doing math

By glifxyz·Created 3 years ago·Updated about a year ago· 65
Image to SDXL compatible WH
  • image
  • width
  • height

SDXL has a quirk that trips up everyone coming from SD 1.5: it was trained at 1024x1024 with a fixed set of aspect ratios, and the model is genuinely picky about it. Generate at some arbitrary resolution and you get artifacts, composition drift, or just a model that's clearly off its game. The accepted practice is to pick the closest native bucket - 1024², 832x1216, 896x1152, and friends - instead of any resolution you feel like. Image to SDXL compatible WH does the picking for you: feed it any image, it measures your aspect ratio and returns the closest SDXL-native width and height. You feed those numbers into an EmptyLatentImage or a resize, and your img2img / ControlNet work suddenly behaves.

How it works

One input: image. The node reads the image's aspect ratio (width ÷ height), then finds the closest match from the fixed table of SDXL training buckets - all 13 of them, covering 1:1, 2:3, 3:4, 5:8, 9:16, 9:19, 9:21 and their landscape mirrors, each at its native pixel count. It returns two INTs: width and height.

Note what it does not do: it doesn't resize, crop, or pad anything. It's a calculator with one job, and it does it because an aspect-ratio-aware calc is exactly what keeps people from hand-rolling 1216x832 and missing the bucket by a hair. The output numbers are the whole product.

How to actually use it

In an img2img or ControlNet workflow: take the image you're conditioning on, run it through this node, and wire the two INTs into an EmptySDXLLatent (or a resize-to-size node) that your sampler consumes. That way the generation canvas is always a true SDXL bucket that matches your source's composition - the standard recipe for "condition on this image without mashing the aspect ratio." If you instead want the condition image itself resized to the bucket, chain the INTs into a resize node before the encoder. The node itself is agnostic about which you do; it just makes the numbers easy.

The nearest-bucket logic is adapted from a community snippet (credited in the source), and the pack keeps a copy so you don't need a separate utility pack just for this. It's dead simple, deterministic, and exactly the kind of thing that's faster to look up than to get wrong.

Install

Ships in ComfyUI-GlifNodes from the glif.app team. ComfyUI Manager → "ComfyUI-GlifNodes", or:

cd ComfyUI/custom_nodes
git clone https://github.com/glifxyz/ComfyUI-GlifNodes

Restart ComfyUI. No models, no dependencies, instant - it's an aspect-ratio table and a min() call.

Where it shines: SDXL img2img, Redux/IP-Adapter conditioning that needs to match source composition, and batch workflows where every image should be snapped to a native bucket before the sampler sees it. If you only use SDXL occasionally, this is the reminder you'll be glad to have.

Categoryimage

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (2)

NameTypeDescription
widthINT
heightINT