PD_BatchCropBlackBorder
Strip black borders off a whole folder of images
- 处理结果
PD_BatchCropBlackBorder (PD_BatchCropBlackBorder) scans every image in a folder, detects a solid black or white border connected to the edges, crops it off, and saves the results. It's the batch version of the pack's single-image PD_CropBorder, and it exists for the classic annoyance: a pile of screenshots, upscaled outputs, or scraped images all wrapped in unwanted letterbox bars.
How it works
For each image, it converts to grayscale and scans inward from all four edges, marking pixels as "border" when they match the target color within a threshold - black means brightness ≤ threshold, white means brightness ≥ 255 − threshold. Once it finds the first non-border pixel from each edge, it crops to that rectangle. The padding input adds extra pixels back around the crop, which is your margin of safety when the content nearly touches the border. threshold (0–255, default 10) controls how strict the color match is - lower is stricter, so a noisy dark border might need a bump up.
If output_path is set, results go there; if it's left empty, it overwrites the originals in place. Read that sentence twice, because it's the one that bites. The node outputs a single message string with a processing report.
The inputs that matter
input_path- the folder to process. Required, typed by hand.border_color-blackorwhite(tooltip: "选择要删除的边框颜色"). One pass handles one color.threshold- strictness of detection, 0–255.padding- pixels kept after the crop, 0–100.output_path- optional. Set it to a new folder unless you genuinely want in-place overwrites.
Installing
Part of the 7BEII/Comfyui_PDuse pack. ComfyUI Manager → search "Comfyui_PDuse" → install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/7BEII/Comfyui_PDuse
cd Comfyui_PDuse
pip install -r requirements.txt
Restart after. No models; it needs opencv-python (for the color handling) plus the pack's standard Pillow/numpy deps.
Gotchas
Set output_path from day one. Overwriting originals is a legit feature - the README even advertises it - but there's no undo, and a bad threshold that crops into your actual content is unrecoverable. Also, "connected to the edges" is doing real work here: interior black regions (a dark logo, a shadow) are not touched, so you don't have to worry about holes being eaten. But an image whose content genuinely reaches the edge will get its content cropped if the border color is close - that's what padding and a stricter threshold are for. Test on a copy of one folder before you let it loose on the real dataset.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| input_path | STRING | — | |
| border_color | COMBO | black | 选择要删除的边框颜色 |
| threshold | INT | 100–255 | 颜色检测阈值,0-255,值越小检测越严格 |
| padding | INT | 00–100 | 裁切后额外保留的边距像素 |
| output_pathopt | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| 处理结果 | STRING | — |