OpenCV copyMakeBorder_0
CopyMakeBorder
- src
- dst
- nparray
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 (usevalue)1= replicate the edge pixels outward (great for seamless-looking padding)2= reflect the image like a mirror4= reflect without repeating the edge row (BORDER_REFLECT_101, what most tools use internally)3= wrap around, tile-style
value- only read whenborderType = 0. It's the fill color, and here's the pack's signature twist: it's aSTRINGparsed with Python'sliteral_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 classicinvalid 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
valuestring 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 viaImage2Nparray(batch 1 only) in,Nparrays2Imageout. - Optional
dstinput is an OpenCV out-parameter; leave it empty. copyMakeBorder_0and_1are the identical MatLike/UMat overload pair - same node, two names. Either works.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — | |
| top | INT | — | |
| bottom | INT | — | |
| left | INT | — | |
| right | INT | — | |
| borderType | INT | — | |
| value | STRING | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |