Image Pad
Padding that brings its own mask
- image
- mask
- image
- mask
Padding a canvas is a two-second job in any image editor, so a node that does it needs a reason to exist. UC_ImagePad's reason: it hands you a placement mask alongside the padded image. That mask is what tells an outpainting or compositing pass exactly where the new canvas is and where the original image sits - which is the difference between an outpaint that fills the right region and one that guesses.
It's the outpainting prep node. You want to extend a 1024 image to 1536 for a wider composition; you pad the sides, and the generated mask (value 1 in the padded zone, 0 over the original) becomes the inpaint/outpaint mask that says "only regenerate the new area." Without that, you'd be hand-drawing a mask that's trivially computable - and this node computes it for you, exactly aligned.
How it works
Two padding modes:
- Explicit:
left/right/top/bottomadd those pixels to each side (defaults 0). - Target size: connect
target_widthandtarget_heightand it proportionally fits and centers the image inside that canvas, usingextra_paddingas an inset margin.
pad_mode picks the fill: edge extends the border pixels (the standard look for outpaint prep), edge_pixel keeps the original edge pixel's color, and color fills with a solid - where color accepts RGB triples, 0–255 or 0.0–1.0, a color name, or a hex code.
The mask input is optional: if you connect your own mask, it gets padded with value 1 outside the image; disconnected, a mask for the added border is created for you. That last clause is the feature - the output mask socket always exists and always describes the padding.
The inputs that matter
For beginners: image, left/right (most outpaints pad sides), pad_mode = edge, and then wire the output mask into your outpaint's mask input. target_width/target_height are the alternative when you think "I want exactly 1536 wide" rather than "add 256 left and 256 right." Outputs: image and mask.
Installing it
ComfyUI Manager → search "ComfyUI-UtilsCollection", or:
cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-UtilsCollection
Restart. Deps: opencv-python, typing-extensions, no models. Newer-API pack - keep ComfyUI updated.
The classic mix-up: connecting one of target_width/target_height does nothing useful - both must be connected for target mode, and the tooltip is explicit that the explicit-pad inputs are ignored when target dimensions are connected. If your padding ignores the numbers you typed, check which mode you're in.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| left | INT | 00–16384 | Pixels added to the left when target dimensions are not connected. |
| right | INT | 00–16384 | Pixels added to the right when target dimensions are not connected. |
| top | INT | 00–16384 | Pixels added above the image when target dimensions are not connected. |
| bottom | INT | 00–16384 | Pixels added below the image when target dimensions are not connected. |
| extra_padding | INT | 00–16384 | Additional padding on every side, or an inset margin when target dimensions are connected. |
| pad_mode | COMBO | edge | edge: Extend the edge pixels. edge_pixel: Extend the edge pixels but keep the original edge pixel color. color: Fill with a solid color. pillarbox_blur: Fill with a blurred version of the image. |
| 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 | Optional source mask padded with value 1 outside the image; disconnected creates a mask for the added border. | |
| target_widthopt | INT | 5120–16384 | Optional final width. Connect both target dimensions to proportionally fit and center the image. |
| target_heightopt | INT | 5120–16384 | Optional final height. Connect both target dimensions to proportionally fit and center the image. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |