Pad Image (KJ/SET)
Add borders that are a color, an edge, or a blurred version of the image
- image
- mask
- images
- masks
Padding is one of those operations you think you'll never need until suddenly every workflow you load wants it - to reach a VAE-friendly size, to add outpainting room, to letterbox an image into a canvas. This node is a port of Kijai's KJNodes ImagePad with a few things added, and it's the cleanest way to grow a canvas in ComfyUI.
The core inputs are exactly what you'd guess: left, right, top, bottom in pixels, and an extra_padding applied to all sides. Then it gets interesting - there are four pad_mode options for what fills the empty space, and a target_width/target_height shortcut that bypasses per-side math entirely.
The modes and the shortcut
- color - fill with the
coloryou specify (hex#RRGGBB, or comma-separated RGB in 0–255 or 0.0–1.0). The default and the simplest. - edge - fill each side with the average color of the nearest image edge. Good for a seamless-ish blend when the subject is solid color.
- edge_pixel - repeat the outermost row/column of actual pixels. Keeps gradients alive across the join.
- pillarbox_blur - the showy one: fills the border with a scaled-up, blurred, desaturated, and dimmed copy of the image itself. Great for previews and social thumbnails where you want context, not black bars.
The shortcut: connect both target_width and target_height, and the node centers the image inside that exact canvas - no mental arithmetic for left vs right. Set one of them to 0 and that dimension keeps the image's own size. Also worth knowing: extra_padding in target mode actually shrinks the source image first (with a high-quality lanczos downscale) so the total lands on the target - a handy trick for fitting into exact dimensions.
The optional mask gets padded in lockstep with the image, and pad_transparency controls the mask value in the padded area - 1.0 fully transparent, 0.0 fully opaque. That's a SET addition over KJNodes, and it's what makes padded-out masks play nicely with compositing instead of dumping a hard black border into your alpha.
Outputs
images (the padded image) and masks (the padded mask). Note the mask convention: 1 = transparent, 0 = opaque, which is the reverse of RGBA alpha.
Installing it
Part of Image Misc:
cd ComfyUI/custom_nodes
git clone https://github.com/set-soft/ComfyUI-ImageMisc
cd ComfyUI-ImageMisc && pip install -r requirements.txt
or ComfyUI Manager → "Image Misc", then restart. Under image/manipulation.
Where people get caught
The target_width/target_height inputs only kick in when both are connected - leave one dangling and the per-side values rule. And if your image has an alpha channel (RGBA), the color pad transparently fills rather than painting over; that's intentional, but it surprises people who expected opaque black. For a one-stop resize-plus-pad that handles aspect ratios too, the sibling Resize Image (KJ/SET) node wraps this one and is usually the better starting point - this node is the raw building block underneath.
Inputs (12)
| 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 | #000000 | Color for fill. Can be an hexadecimal (#RRGGBB). Can comma separated RGB values in [0-255] or [0-1.0] range. |
| maskopt | MASK | — | |
| target_widthopt | INT | 5120–16384 | Connect both `target` inputs If 0 the size of the image is used Overrides left/right/top/bottom |
| target_heightopt | INT | 5120–16384 | Connect both `target` inputs If 0 the size of the image is used Overrides left/right/top/bottom |
| pad_transparencyopt | FLOAT | 1.00–1 | The transparency for the padded area for all modes except `edge_pixel`.1.0 is fully transparent, 0.0 is fully opaque. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| images | IMAGE | — |
| masks | MASK | — |