Nodes/ComfyUI-ImageAutosize/Image/Mask Autosize
ComfyUI Node

Image/Mask Autosize

Normalize any input image for diffusion

By SparknightLLC·Created about a year ago·Updated 26 days ago· 0
Image/Mask Autosize
  • image
  • resized
  • width
  • height
  • scale_x
  • scale_y
  • transform
max_size1280
min_size512
divisible_by32
interpolation_modelanczos
crop_modecenter
constraint_prioritymin_size

If you've ever run a folder of mixed-size photos through img2img or ControlNet, you know the drill: every image wants a different width and height, so you either stretch it, or you keep editing the resolution fields like it's a part-time job. Image Autosize is the "set and forget" answer to that. You drop it in front of whatever consumes your input image, tell it roughly what you want once, and it normalizes every frame - resizing, upscaling if needed, and cropping to model-friendly dimensions - so you never touch the numbers again.

It comes from a tiny pack called ComfyUI-ImageAutosize, and it has a fun pedigree: the author, SparknightLLC, is the developer behind Unprompted, the big Automatic1111 dynamic-prompting extension, and this node is a direct port of that tool's [[img2img_autosize]] shortcode. So this is a real workflow that somebody was already shipping daily, re-skinned for ComfyUI's graph.

Why it exists

Diffusion models are picky about resolution in a way that's easy to forget when you work in a UI. Checkpoints are trained at fixed sizes, the latent space works best when dimensions are multiples of 8, and some video models go further - LTX-2.3, for instance, hard-requires width and height divisible by 32 and errors out off-grid. Feed a 1440x810 photo straight into an img2img pass and you're rolling dice on whether it stretches, crops, or just behaves badly. This node does the normalization step that every serious preprocessing chain needs.

How it works

The node takes your input and computes one final target size from three constraints:

  • max_size (default 1280): the larger dimension gets resized down to this, keeping aspect ratio. Your max cap.
  • min_size (default 512): after that, if the smaller dimension is under this, it gets upscaled up to it. Your floor - handy when input images are tiny.
  • divisible_by (default 32): both final dimensions get rounded to the nearest multiple of this.

Then crop_mode decides what to do about the rounding. Because rounding a resize to a multiple of 32 changes the aspect ratio a hair, the node resizes and then crops from an anchor - center (default), an edge, or a corner - to land exactly on the divisible dimensions. Set it to none to skip cropping entirely, at the cost of a slightly non-uniform scale. interpolation_mode defaults to lanczos, which is the right choice for photos; nearest is there if you're resizing masks and want hard edges.

The inputs that actually matter

You'll tune three of these and forget the rest:

  • max_size - the cap that keeps huge inputs from blowing up your VRAM.
  • min_size - the floor that keeps tiny inputs from looking mushy.
  • divisible_by - leave at 32 unless you know your model wants 8 or 16.

The four outputs are image (wire it into whatever's next - a VAE encode, a ControlNet preprocessor, a second sampler), plus width, height, and multiplier. That last one is the sleeper feature: multiplier is the scale factor applied to the original, so you can feed the same image through the node twice (once as image, once as mask) and resize a mask in perfect sync with its source.

Installing it

Open ComfyUI Manager, search ComfyUI-ImageAutosize, and hit install. Or do it by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/SparknightLLC/ComfyUI-ImageAutosize.git

Then restart ComfyUI. There's nothing else to download - no model files, no third-party dependencies (the pack's pyproject.toml declares dependencies = [], meaning it leans entirely on ComfyUI's existing Pillow/torch stack). The node shows up under the image category.

Gotchas

Two things trip people up. First, crop_mode set to none means the aspect ratio is not perfectly preserved after divisibility rounding - if your mask and image both pass through with none, they can drift apart. Keep an anchored crop mode when alignment matters. Second, the pack has been moving fast: a recent 0.3.0 rewrite targets ComfyUI's newer V3 node API, renamed the display to "Image/Mask Autosize", accepts masks directly, and replaced the multiplier output with scale_x/scale_y. If your installed copy shows different outputs than the ones above, you're on the newest build - the sizing logic is the same.

It's not going to change your life if you only process one fixed-resolution image. But the moment you batch, or hand a workflow to someone with different source files, this is the node that quietly stops a whole class of "why is my output stretched" threads.

Categoryimage

Inputs (7)

NameTypeDefaultDescription
imageCOMFY_MATCHTYPE_V3The image or mask to resize.
max_sizeINT12801–8192Longer-dimension target used to calculate one candidate resize scale.
min_sizeINT5121–4096Shorter-dimension target used to calculate one candidate resize scale.
divisible_byINT321–8192Rounds both output dimensions to the nearest multiple of this value.
interpolation_modeCOMBOlanczosInterpolation algorithm used for resizing.
crop_modeCOMBOcenterAnchored modes preserve aspect ratio by cropping. Pad preserves aspect ratio with reversible padding. None stretches to the output dimensions.
constraint_priorityCOMBOmin_sizeChooses the candidate scale. min_size uses the larger scale; max_size uses the smaller scale. Divisibility rounding runs afterward.

Outputs (6)

NameTypeDescription
resizedCOMFY_MATCHTYPE_V3
widthINT
heightINT
scale_xFLOAT
scale_yFLOAT
transformAUTOSIZE_TRANSFORM