Nodes/ComfyUI-bitpoet-IG4Inpaint/Scale Image to Multiples of Base
ComfyUI Node

Scale Image to Multiples of Base

The Fastest Way to Make an Image Actually Encode

By BitPoet·Created 3 months ago·Updated 3 months ago· 1
Scale Image to Multiples of Base
  • image
  • image
multiple_of64
method

Drop a reference image into ComfyUI, and sooner or later the VAE will spit out a latent with dimensions that don't divide cleanly, and your sampler will punish you for it with warped edges or a hard error. Scale Image to Multiples of Base fixes the image before the encoder ever sees it: it returns a version whose height and width are both multiples of whatever number you give it, no math on your part.

How it works

Trivial, in the good way. It computes the largest multiple of multiple_of that's smaller than or equal to the current height and width, then does one of two things to get there:

  • center crop - slices a centered rectangle at that size. You lose the edges, but every pixel you keep is original.
  • rescale - bilinear-interpolates the whole image down to that size instead. Nothing gets cut off; you just lose a little sharpness.

That's the entire mechanism. It only ever shrinks - there's no upscaling-to-multiple here.

The inputs and output

  • image (IMAGE) - whatever you loaded, from Load Image or an earlier node.
  • multiple_of (INT, default 64, 1–256) - the target modulus. 64 is the safe default: it's a multiple of 8 and 16, so the result is valid for SDXL, Flux 2, and Ideogram 4 alike. Drop it to 16 if you want to keep more of a small image.
  • method (enum: center crop / rescale) - choose your tradeoff.

The single output is image, which you feed into a VAE encode or straight into an img2img/inpaint pipeline. Clean multiples in, clean latents out.

Where you'd actually use it

Anywhere a model or VAE is picky about dimensions. The pack it ships in uses it the same way you will: reference images rarely arrive at the model's native resolution or aspect ratio, and pre-scaling them to a multiple of the VAE's downsample factor (16× for the Flux 2 / Ideogram 4 VAE) avoids a whole class of encode-time surprises. It's also handy before an inpaint pass when your source image is some oddball phone-screenshot size.

Installing it

ComfyUI Manager (search "ComfyUI-bitpoet-IG4Inpaint"), or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/BitPoet/ComfyUI-bitpoet-IG4Inpaint

Restart ComfyUI. No dependencies, no models - this node is plain torch code, so it works regardless of which models you run.

Gotchas (one of them is real)

The honest warning: the rescale method is broken in the shipped code. The node calls torch.nn.functional.interpolate but the module never imports torch.nn.functional, so the moment you select "rescale" you get NameError: name 'F' is not defined. This isn't your fault and it isn't a setup problem - it's a typo-class bug in the pack (the author flagged the whole pack as alpha). Use center crop, which works fine, or if you want rescale, add import torch.nn.functional as F to the top of custom_nodes/ComfyUI-bitpoet-IG4Inpaint/nodes.py.

Second, smaller one: if the image is smaller than multiple_of in either axis, both methods compute a zero-sized result and crash. Keep multiple_of below your smallest image dimension, or upscale the image first.

Categoryimage

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
multiple_ofINT641–256
methodCOMBO2 options: center crop, rescale

Outputs (1)

NameTypeDescription
imageIMAGE