Nodes/ComfyUI Pad to Multiple/Image Pad To Multiple
ComfyUI Node

Image Pad To Multiple

Pad It to the Model's Grid Instead

By mr-september·Created 6 months ago·Updated 3 months ago· 1
Image Pad To Multiple
  • image
  • image
  • width
  • height
  • mask
multiple_of16
pad_colorblack
direction_1Bottom
direction_2Right

Padding is the workaround your img2img has been quietly lying to you about

Here's a situation everyone hits eventually: you feed a 513×513 image into a Flux or DiT workflow, and the model - or the node feeding it - decides that off-grid dimensions don't exist. The usual suspects then kick in. Something stretches it, something center-crops it, and your subject quietly loses its face or its edges, and you have to hunt down which node did the damage. Image Pad To Multiple (ImagePadToMultiple) from the one-node pack ComfyUI Pad to Multiple refuses to play that game. It adds solid-colored padding on the edges until the image is divisible by whatever number you name. Nothing moves, nothing warps, nothing gets cut.

That matters more than it sounds. DiT-era models like Flux and SD3 want inputs on specific grids (multiples of 16, 32, 64 depending on who you ask), and the difference between "the tool silently resized" and "it told you exactly what it added" is the difference between being able to recomposite your output over your source and not. If you generate from an off-grid input and then try to paste the result back onto the original image, a stretched or cropped source is a nightmare. Padding keeps every original pixel exactly where it was, and the colored border makes the added area trivial to spot and trim.

How it actually works

The whole node is one small function, and its logic is easy to trust: it reads your image's width and height, computes how many pixels are missing to reach the next multiple, and pads each axis independently - the X and Y paddings are never shared or forced equal. Then it fills the added area with a constant color using PyTorch's F.pad under the hood. No model files, no weights, no API. If your image is already on-grid, it returns the image untouched with an empty mask - the node is a no-op and proud of it.

That last detail, the mask, is the reason to pick this over just eyeballing a crop: along with the padded image it also outputs the padded width, height, and a mask where 1.0 marks padding and 0.0 marks your original content. The mask output only landed after someone on r/comfyui pointed out that ComfyUI's core Pad Image for Outpainting node has one too - so you can use it to feed an inpaint workflow or cut back to your original bounds programmatically instead of guessing.

The inputs that matter

Four inputs, and you mostly care about two of them:

  • multiple_of (INT, default 16, range 1–256) - the grid you're padding to. The README's suggested starting points: 64 for SD 1.5 / DiT, 8 for SDXL, 16 or 32 for Flux / SD3. If your model complains about dimensions, that's the dial.
  • pad_color - black, white, or gray. Gray reads well against most images.
  • direction_1 and direction_2 - each picks Top, Bottom, Left, Right, Left-Right, or Top-Bottom, defaulting to Bottom + Right. The handy trick: pick the same direction for both slots and it pads that axis only, so you can fix height without touching width.

Outputs are image, width, height, and mask. width and height tell you exactly how much to trim later, and mask is your inpaintable record of where the padding is.

Installing it

It's a tiny, zero-dependency pack. Easiest route: ComfyUI Manager, search "Pad to Multiple", install, restart. Or from a terminal:

cd ComfyUI/custom_nodes
git clone https://github.com/mr-september/comfyui-pad-to-multiple.git

Then restart ComfyUI. No requirements.txt to fight, no model downloads - just PyTorch, which you already have. This is one of the rare custom nodes that can't break your environment, because it barely touches it.

Where people get tripped up

The honest limits: the padding is solid color only, so if you need alpha-transparent padding for compositing, this node isn't it. And it adds, it never removes - if your image is slightly too big for the grid rather than too small, you're on the wrong tool. The other gotcha is forgetting the whole point: padding gets you into the model's grid without touching your content, but the padded border is still padding. Crop it back off after generation (the width/height outputs are there for exactly that), or run the mask through an inpaint pass if you want the border gone but the size kept. Skip that step and you'll wonder why every output has a gray or black frame.

Categoryimage/transform

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
multiple_ofINT161–256
pad_colorCOMBOblack3 options: black, white, gray
direction_1COMBOBottom6 options: Top, Bottom, Left, Right, Left-Right, Top-Bottom
direction_2COMBORight6 options: Top, Bottom, Left, Right, Left-Right, Top-Bottom

Outputs (4)

NameTypeDescription
imageIMAGE
widthINT
heightINT
maskMASK