ComfyUI Node

Image Pad

Padding that brings its own mask

By silveroxides·Created 2 months ago·Updated about 7 hours ago· 24
Image Pad
  • image
  • mask
  • image
  • mask
left0
right0
top0
bottom0
extra_padding0
pad_modeedge
color0, 0, 0
target_width512
target_height512

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/bottom add those pixels to each side (defaults 0).
  • Target size: connect target_width and target_height and it proportionally fits and centers the image inside that canvas, using extra_padding as 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.

Categoryadvanced/image

Inputs (11)

NameTypeDefaultDescription
imageIMAGE
leftINT00–16384Pixels added to the left when target dimensions are not connected.
rightINT00–16384Pixels added to the right when target dimensions are not connected.
topINT00–16384Pixels added above the image when target dimensions are not connected.
bottomINT00–16384Pixels added below the image when target dimensions are not connected.
extra_paddingINT00–16384Additional padding on every side, or an inset margin when target dimensions are connected.
pad_modeCOMBOedgeedge: 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.
colorSTRING0, 0, 0Color as RGB values in range 0-255 or 0.0-1.0, or color name or hex code
maskoptMASKOptional source mask padded with value 1 outside the image; disconnected creates a mask for the added border.
target_widthoptINT5120–16384Optional final width. Connect both target dimensions to proportionally fit and center the image.
target_heightoptINT5120–16384Optional final height. Connect both target dimensions to proportionally fit and center the image.

Outputs (2)

NameTypeDescription
imageIMAGE
maskMASK