ImagePad KJ
Add borders, letterbox, and set up outpainting
- image
- mask
- images
- masks
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.
colorfills with a solid color (set it below).edgeandedge_pixelstretch the border pixels outward so the pad blends with the image instead of being a hard line.pillarbox_blurfills 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 wantedge; for presentation,pillarbox_blurlooks the most natural. - color - the fill color (as a string like "0, 0, 0") when you're in
colormode. - 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.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| left | INT | 00–16384 | — |
| right | INT | 00–16384 | — |
| top | INT | 00–16384 | — |
| bottom | INT | 00–16384 | — |
| extra_padding | INT | 00–16384 | — |
| pad_mode | COMBO | 4 options: edge, edge_pixel, color, pillarbox_blur | |
| color | STRING | 0, 0, 0 | Color as RGB values in range 0-255 or 0.0-1.0, or color name or hex code |
| maskopt | MASK | — | |
| target_widthopt | INT | 5120–16384 | — |
| target_heightopt | INT | 5120–16384 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| images | IMAGE | — |
| masks | MASK | — |