Nodes/ComfyUI_Eclipse/Image Align Size
ComfyUI Node

Image Align Size

The node that fixes 'size not divisible by 31' and its cousins

By r-vage·Created 10 months ago·Updated a day ago· 31
Image Align Size
  • image
  • mask
  • image
  • mask
  • width
  • height
divisor31
modeshrink
pad_fillblack
resize_methodlanczos

If you've ever run BiRefNet or a rembg pipeline and hit some variant of "input size must be divisible by 31," you know the exact pain this node exists to kill. Image Align Size nudges an image's dimensions so they're divisible by a given number, and it does it three different ways so you don't wreck the pixels doing it. The default divisor is 31, which is no accident - that's what BiRefNet's patch rearrangement needs.

Why you care: a pile of models have hard divisibility requirements, and they don't agree. The tooltip gives you the cheat sheet - 31 for BiRefNet, 8 for a VAE, 64 for some upscalers. When a model errors with "dimension not divisible by X," you don't want to hand-resize in Photoshop and hope; you want a node that fixes it deterministically and reports what it did.

The three modes, and when to use which

  • shrink (default) - center-crops to the nearest smaller valid size. No quality loss, but you lose a sliver of edge. Right choice when the divisibility miss is a few pixels.
  • grow - pads to the nearest larger valid size. Nothing gets cut, but you introduce padding, so pick your fill (black, white, or edge_replicate - edge replication usually looks least like a border).
  • resize - interpolates to the nearest valid size, which means real scaling. Use it when the miss is big enough that cropping or padding would distort the composition.

There's also an optional mask input that gets aligned in lockstep with the image - genuinely useful if you're aligning before a masked operation and need the mask to stay registered with the pixels. Outputs are the aligned image, the aligned mask (empty if you didn't connect one), and width/height ints you can feed downstream.

The math underneath is boring in the good way: round down, round up, or round nearest to a multiple of the divisor, minimum size = the divisor itself. No surprises.

Where it slots into a workflow

Put it in front of anything picky. The canonical chain: Load Image → Align Size (divisor 31) → BiRefNet/rembg → paste back. It's also a cheap guard before a VAE encode or an upscaler that demands multiples of 64 - the kind of deterministic pixel op the KB's post-processing doc loves: milliseconds, zero model runs, no seed lottery.

Installing

Part of the ComfyUI_Eclipse pack from r-vage. Via Manager: search ComfyUI_Eclipse, or:

cd ComfyUI/custom_nodes
git clone https://github.com/r-vage/ComfyUI_Eclipse

Restart, find it under Eclipse → Image → Transforms. Standard deps; run pip install -r requirements.txt on a fresh environment. Eclipse targets current ComfyUI (frontend 1.51.2+ for the polish) and its v4.0 cleanup dropped legacy RvTools_v2 nodes - the built-in Workflow Migration Tool handles old workflows.

The trap to avoid: defaulting to resize when a 2-pixel crop would do. Shrink first, resize only when the alignment actually costs you real estate. And if a model is still complaining after alignment, double-check the other requirement - BiRefNet wants both dimensions divisible by 31, and it'll take whichever one you forgot.

Category🌒 Eclipse/ Image/Transforms

Inputs (6)

NameTypeDefaultDescription
imageIMAGEInput image to align.
divisorINT311–512Target divisibility. E.g. 31 for BiRefNet, 8 for VAE, 64 for some upscalers.
modeCOMBOshrinkHow to adjust dimensions: • shrink — center-crop to nearest smaller valid size (no quality loss) • grow — pad to nearest larger valid size • resize — interpolate to nearest valid size
pad_fillCOMBOblackFill method when mode is 'grow': • black — pad with black pixels • white — pad with white pixels • edge_replicate — replicate edge pixels
resize_methodCOMBOlanczosInterpolation method when mode is 'resize'.
maskoptMASKOptional mask — adjusted together with the image.

Outputs (4)

NameTypeDescription
imageIMAGEAligned image with dimensions divisible by divisor.
maskMASKAligned mask (empty if no mask input).
widthINTOutput image width.
heightINTOutput image height.