ComfyUI Node Runs on cloud

ImagePad KJ

Add borders, letterbox, and set up outpainting

By kijai·Created 3 years ago·Updated a day ago· 2,908
ImagePad KJ
  • image
  • mask
  • images
  • masks
left0
right0
top0
bottom0
extra_padding0
pad_mode
color0, 0, 0
target_width512
target_height512

ImagePadKJ adds space around an image. That's it, and it's more useful than it sounds. The obvious use is putting a border on something, but the reason it earns its place in real workflows is outpainting: to extend an image beyond its edges, you first pad it with blank space, then let a model paint into that new area. This node is the "pad it first" step, and it hands you a matching mask of exactly the region you added so the inpaint knows where to work.

What it does

You tell it how many pixels to add on each side and how to fill them. The image grows, and if you passed a mask in, that grows too, staying aligned. The fill mode is where the design shows: you're not stuck with a flat color.

The inputs that matter

  • left / right / top / bottom - pixels to add on each edge, independently. Pad just the sides for a widescreen crop, or all four for a uniform border.
  • pad_mode - how the new pixels are filled, and this is the interesting choice. color fills with a solid color (set it below). edge and edge_pixel stretch the border pixels outward so the pad blends with the image instead of being a hard line. pillarbox_blur fills the padding with a blurred continuation of the image - the exact trick you see behind vertical phone videos shown on a wide screen. For outpainting you often want edge; for presentation, pillarbox_blur looks the most natural.
  • color - the fill color (as a string like "0, 0, 0") when you're in color mode.
  • extra_padding - a uniform extra margin added on top of the per-side values.

There's an optional mask input (padded to match) and target_width / target_height, which let you pad up to a specific canvas size instead of specifying pixel amounts by hand - handy when you need everything on, say, a 1024x1024 frame regardless of the input's shape.

Outputs are the padded images and masks. The mask is the key output for outpainting: it marks the added region, so you wire it into your inpaint sampler as the area to generate.

Installing KJNodes

ComfyUI Manager: Custom Nodes Manager, search "KJNodes for ComfyUI", install, restart. Manual: cd ComfyUI/custom_nodes && git clone https://github.com/kijai/ComfyUI-KJNodes, then pip install -r ComfyUI-KJNodes/requirements.txt (portable: python_embeded\python.exe -m pip install -r ComfyUI\custom_nodes\ComfyUI-KJNodes\requirements.txt), restart. No models needed.

Common issues

The mistake that bites: forgetting the model needs valid dimensions. If you pad by odd amounts and then hand the result straight to a sampler, you can land on a size that isn't a clean multiple of 8 and get an error or a subtle shift. Pad to sizes that stay model-friendly, or run a resize/round step after.

For outpainting specifically, a hard color fill gives the model a sharp seam to fight against; edge fill usually produces cleaner continuations because there's no abrupt boundary. And if the new region comes out ignoring your existing image entirely, check that you actually wired the padded mask into the sampler - padding the image without using the mask just gives the model a blank border it has no instruction to fill coherently.

CategoryKJNodes/image

Inputs (11)

NameTypeDefaultDescription
imageIMAGE
leftINT00–16384
rightINT00–16384
topINT00–16384
bottomINT00–16384
extra_paddingINT00–16384
pad_modeCOMBO4 options: edge, edge_pixel, color, pillarbox_blur
colorSTRING0, 0, 0Color as RGB values in range 0-255 or 0.0-1.0, or color name or hex code
maskoptMASK
target_widthoptINT5120–16384
target_heightoptINT5120–16384

Outputs (2)

NameTypeDescription
imagesIMAGE
masksMASK