Nodes/opencv-comfyui/OpenCV copyMakeBorder_0
ComfyUI Node

OpenCV copyMakeBorder_0

CopyMakeBorder

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV copyMakeBorder_0
  • src
  • dst
  • nparray
top
bottom
left
right
borderType
value

copyMakeBorder_0 grows an image by adding a border of pixels around it - exactly the "extend the canvas" operation you'd otherwise do in Photoshop, now inside the graph. Feed it an nparray, tell it how many pixels to add on each side and how to fill them, and it hands back a bigger image. It's from the opencv-comfyui pack, a straight cv2.copyMakeBorder wrapper, and unlike a lot of auto-generated nodes this one earns its place: padding before resizing, adding margins so a model's aspect-ratio constraint doesn't force a crop, or just giving yourself room to composite.

The inputs are src (NPARRAY), top, bottom, left, right (each INT - the border thickness on each side), borderType (INT), and value (STRING). Output is a single nparray, the padded image.

The two inputs that actually matter

  • borderType - how the border is filled. This is OpenCV constant land, so have the table handy:
    • 0 = constant color (use value)
    • 1 = replicate the edge pixels outward (great for seamless-looking padding)
    • 2 = reflect the image like a mirror
    • 4 = reflect without repeating the edge row (BORDER_REFLECT_101, what most tools use internally)
    • 3 = wrap around, tile-style
  • value - only read when borderType = 0. It's the fill color, and here's the pack's signature twist: it's a STRING parsed with Python's literal_eval, so you type it as a Python literal. (255, 255, 255) for white, [0, 0, 0] for black, or a 4-tuple for BGRA. Get the syntax wrong - forget a parenthesis, use {} instead of [] - and you get the pack's classic invalid syntax (<unknown>, line 0) error. That error is the README's known symptom for exactly this.

If you're padding to hit a size target, borderType = 1 (replicate) is usually the visual winner for a photo, because it avoids a hard colored seam; constant black or white is the safe default for compositing work.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-python-contrib

Or ComfyUI Manager → search opencv-comfyui → restart. No model files.

Troubleshooting

  • The value string syntax - this is the most common place beginners trip on this node. Python literals only: (255, 255, 255) or [0,0,0].
  • Remember the color bridge: this pack is BGR. Your white (255, 255, 255) is fine (grays are symmetric), but a colored border like (255, 0, 0) will come out as OpenCV blue until you account for ordering. Convert via Image2Nparray (batch 1 only) in, Nparrays2Image out.
  • Optional dst input is an OpenCV out-parameter; leave it empty.
  • copyMakeBorder_0 and _1 are the identical MatLike/UMat overload pair - same node, two names. Either works.
Categoryimage/OpenCV

Inputs (8)

NameTypeDefaultDescription
srcNPARRAY
topINT
bottomINT
leftINT
rightINT
borderTypeINT
valueSTRING
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY