Custom auto size
Fit any image to the pixel count your model was trained on
- image
- width
- height
The whole job in one sentence
CustomAutoSize looks at an image, asks you how many total pixels you want, and hands back a width and height that hit that budget while keeping the aspect ratio. It never touches the image - it's a resolution calculator, not a resizer - so you wire its numbers into the rest of the graph and let them decide the latent's dimensions.
Why reach for it: models are trained with a rough pixel budget in mind, and the moment you generate way past it you get the classic failure modes - duplicated anatomy, tiling, stretched limbs. SDXL's native budget is 1,048,576 pixels (1024×1024), SD 1.5's is 262,144 (512×512). If you're running img2img or ControlNet off a source image that's some arbitrary size, this node converts that shape onto a sane pixel budget before it ever hits the sampler.
How it works
It's a few lines of pure math, no models, no downloads:
scale = floor(sqrt(latent_size / (width * height)) * 1000) / 1000
new_width = floor(width * scale)
new_height = floor(height * scale)
The scale factor is rounded down to three decimals, so a 1000×500 image at the default budget comes back 1448×724 - total 1,048,352 pixels, a hair under your target of 1,048,576 because of all that flooring. It goes both directions, too: a 512×512 image upscales to 1024×1024, and a 2048×2048 image shrinks to 1024×1024.
The inputs that matter
There are exactly two, and you only touch one of them:
- image - the reference image whose shape you're matching.
- latent_size - total pixels you want, an INT, default 1048576 (i.e. 1 MP, SDXL's budget). Drop it to 262144 for SD 1.5, or whatever your model was trained on.
Outputs are width and height (both INT). They feed straight into the width/height slots of an EmptyLatentImage, or any node that takes dimensions.
Install
This pack is dependency-free - a two-file, pure-Python repo, no requirements.txt, no model downloads. Easiest way: ComfyUI Manager, search "ComfyUI-autosize", install, restart. Or do it by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/chakib-belgaid/ComfyUI-autosize
Then restart ComfyUI. It'll be under the Image Size category.
Where people trip
- Outputs aren't snapped to multiples of 8. 1448×724 is off the clean grid latent space prefers. ComfyUI runs it fine, but if you're a multiples-of-8 person, budget a resize node after.
- It's a no-op if your image already matches the budget. Feed it a 1024×1024 square at the default and you get 1024×1024 back. That's correct, just don't expect magic.
- It won't resize your image for you. If you wire these dims into a latent but keep feeding the full-res source image through a VAE, your shapes won't line up. Use the dims in EmptyLatentImage, or resize the source image to match.
Honest take: this is a tiny utility from an essentially anonymous pack (zero impressions, zero reddit footprint, a single 2024 commit) - but for "rescale to N megapixels, keep the ratio" it does exactly one thing, with zero install friction and nothing to break. If you later want snapping to 8s and a richer size picker, you'll graduate to a bigger utility pack. Until then, this works.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| latent_size | INT | 1048576 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| width | INT | — |
| height | INT | — |