Nodes/comfyui-auto-size/πŸ“ Auto Size
ComfyUI Node

πŸ“ Auto Size

Stop hand-typing resolutions your model was never trained on

By jluo-githubΒ·Created 7 months agoΒ·Updated 5 months agoΒ· 0
πŸ“ Auto Size
  • image
  • mask
  • image
  • mask
  • width
  • height
  • size
β—„modelqwen-imageβ–Ί
β—„sizeFull Custom (Use Inputs Below)β–Ί
β—„custom_longer_size0β–Ί
β—„custom_ratio1:1β–Ί
β—„crop_methodCenter Cropβ–Ί
β—„scale_methodlanczosβ–Ί

You've been there: you drop a reference image into an img2img workflow, and the sampler quietly resizes it to some default - or worse, you type 1328x1328 into a resolution box and hope. Every modern model family has a native resolution and a size multiple it was trained on. Qwen-Image wants 28px multiples, Illustrious, Z-Image and Flux want 32px. Get it wrong and you're fighting the model instead of riding it. πŸ“ Auto Size exists so you stop typing and start picking.

What it does

Auto Size takes an existing image (and an optional mask) and resizes it to a model-aligned resolution - the one the model you're about to feed actually expects. You pick the target model and a size from a dropdown, and out comes a correctly-sized image, plus the width and height as plain integers you can wire into anything else.

How it works

The whole thing is a thin wrapper around a resolution table in the pack's utils/presets.py. The size dropdown holds per-family presets - Qwen, Illustrious, Z-Image, Flux, plus a set of "Fav" presets the author keeps visible no matter which model you pick. Each entry is literal pixels: Qwen - 1:1 (1328x1328), Illustrious - 9:16 (768x1344), that sort of thing.

If presets aren't enough, pick Full Custom (Use Inputs Below) and set two things:

  • custom_longer_size - the longer side in pixels (0 means "use the preset")
  • custom_ratio - an aspect ratio like 9:16 or 3:2

The node computes the other side, then snaps the result to your model's multiple - round(width / multiple) * multiple, with a floor at the multiple itself. So Qwen gets 28-aligned sizes, everything else gets 32-aligned. Where people get tripped up: snapping only happens in custom mode. Preset values are used verbatim, which is fine because they're already aligned.

crop_method is the knob that matters for aspect mismatches. Center Crop, Top-Left Crop and Bottom-Right Crop scale the image to cover the target then crop the named edge; Scale to Fit letterboxes with black bars; Stretch to Fill just distorts it to fit. scale_method is interpolation - lanczos is the default and it's the right call for downscaling.

Inputs and outputs

The three inputs you'll actually touch: model (qwen-image, illustrious, z-image, flux), size (preset or Full Custom), and custom_longer_size when you want a custom size. image and mask are both optional - leave image empty and the node outputs a black frame at the target size, which makes it a handy pure resolution source.

Outputs: image, mask, width, height, and size (a string like 1328x1328). The node is marked as an output node, so the resolved size shows up as text in the UI - a nice confirmation that the math did what you expected. The width/height integers are the real value: wire them into downstream resolution inputs and everything stays in lockstep.

Installing it

Same routine as any custom node, and there's nothing heavy to download:

cd ComfyUI/custom_nodes
git clone https://github.com/jluo-github/comfyui-auto-size.git

Restart ComfyUI and reload the browser. Or search "Auto Size" in ComfyUI Manager. The only declared dependency is torch>=2.0, which you already have - no model files, no API keys, no Python package install. This is one of those rare packs where the README is honest about scope.

Gotchas

The dropdown filtering (only showing Qwen presets when Qwen is selected) is JavaScript. The resolution math is pure Python, so if the JS fails to load - headless runs, API calls - the node still works fine, you just see all 51 presets. And one honest caveat: the model list is fixed and small. If your model isn't one of the four, pick the closest family or use Full Custom and check the multiple yourself. For a zero-dependency utility, that's a fair trade.

Categoryimage/AutoSize

Inputs (8)

NameTypeDefaultDescription
modelCOMBOqwen-image4 options: qwen-image, illustrious, z-image, flux
sizeCOMBOFull Custom (Use Inputs Below)51 options: Full Custom (Use Inputs Below), Qwen - 1:1 (1328x1328), Qwen - 9:16 (928x1664), Qwen - 16:9 (1664x928), Qwen - 3:4 (1104x1472), Qwen - 4:3 (1472x1104), +45
custom_longer_sizeINT00–8192β€”
custom_ratioCOMBO1:115 options: 1:1, 1:2, 2:1, 2:3, 3:2, 3:4, +9
crop_methodCOMBOCenter Crop5 options: Center Crop, Top-Left Crop, Bottom-Right Crop, Scale to Fit, Stretch to Fill
scale_methodCOMBOlanczos4 options: lanczos, bilinear, bicubic, nearest
imageoptIMAGEβ€”
maskoptMASKβ€”

Outputs (5)

NameTypeDescription
imageIMAGEβ€”
maskMASKβ€”
widthINTβ€”
heightINTβ€”
sizeSTRINGβ€”