Auto size for SDXL
Snap any image onto an SDXL bucket so you stop fighting the model
- image
- width
- height
The short version
SDXLAutoSize looks at whatever image you hand it and returns the closest resolution from SDXL's native bucket list, keeping the aspect ratio as close as it can. It doesn't resize anything - it's a measuring stick that outputs two integers, width and height, for you to feed into an EmptyLatentImage or a resize step.
The context that makes it worth caring about: SDXL wasn't trained on arbitrary sizes. It was trained at 1024×1024 plus a fixed set of aspect-ratio variants, and every bucket holds the same 1,048,576 total pixels. Generate way off those shapes and you get the classic "Resolution wrong" symptoms the community hits constantly - duplicated anatomy, tiling, stretched limbs. This node's whole pitch is "pick a bucket the model actually saw in training." It's the same philosophy Fooocus baked in with its hardcoded resolution list, just exposed as a node.
The buckets
All of them are 1 MP total:
- Square: 1024×1024
- Widescreen: 2048×512, 1920×512, 1600×640, 1536×640, 1472×704, 1344×768
- Portrait: 960×1024, 896×1152, 832×1216, 768×1280, 704×1408, 640×1536
How it works
It computes your image's width/height ratio, rounds it to three decimals, and picks the largest bucket ratio that's strictly less than yours. That strictness is the one quirk worth knowing: exact matches get pushed down a notch. Feed it a 1024×1024 square and you get 960×1024 back, not the identical 1024×1024. Feed it a 16:9 video frame and you get 1344×768 - exactly 16:9, nice. Feed it 3:2 and there's no 3:2 bucket at all, so it falls to 1024×1024, a real shape change; crop accordingly.
Inputs and outputs
- image - the only input, a reference image whose shape you're matching. It's never modified.
- Outputs width and height (both INT).
For text2img, wire them into EmptyLatentImage. For img2img or ControlNet, resize your source image to those dims first so the latent you encode matches what the model expects - that's where the bucket actually earns its keep.
Install
No dependencies, no model downloads - it's a pure-Python two-file pack. ComfyUI Manager, search "ComfyUI-autosize", install, restart. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/chakib-belgaid/ComfyUI-autosize
Restart ComfyUI and it shows up under Image Size.
Gotchas
The strict-less-than matching is the thing that'll surprise you - square inputs land on 960×1024, and in-list ratios like 2.4 (1536×640) still drop a notch because equality doesn't count. There's no 3:2 or 16:10 bucket, so those inputs jump further than you'd like. And be honest about the pack's footprint: it has zero impressions and zero reddit presence, one commit from 2024. It's a 13-line node that does one narrow thing with nothing to break. If you need a bigger bucket list or rounded-to-multiples-of-8 output, you'll find richer sizing nodes in the big utility packs - but for "give me the SDXL resolution closest to this image," this is the minimal thing that works.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| width | INT | — |
| height | INT | — |