🍒Transparent_Area_Cropper✀透明区域裁剪
Trim the empty space around a mask element
- 图片
- 蒙版
- 合并Alpha图片
- 裁剪后图片
- 透明蒙版
Transparent_Area_Cropper is the "get rid of the dead space" node. You've got an image with a subject sitting in a sea of white (or transparent) padding, you've got a mask that says where the subject actually is, and you want the canvas shrunk to just the content - like Photoshop's canvas-resize-to-content, minus the manual clicking.
It's the crop step in the pipeline this pack clearly cares about: remove background → mask the subject → trim the canvas → get a tidy element. It's also handy for batch datasets where every image has different amounts of padding and you want them all normalized to their content.
The mechanism. It reads the mask's bounding box and crops the image to it, but the behavior is careful about mask conventions. The author's docs expect a white-background, black-element mask (白底黑元素 - white background, black object). The node inverts it internally to find the content region, crops both image and mask, and then - depending on your settings - either hands you the tight rectangle or pads it to a centered square. Importantly, it only resizes the canvas: the docstring stresses that image content is never modified, just the canvas around it.
Inputs. All labeled in Chinese - the author's naming, not a translation error:
图片(image) - the source image.蒙版(mask) - the mask marking the element.正方形输出(square output) - BOOLEAN, default on. When on, the result is a centered square canvas sized to the longer side of the content; off gives you the exact bounding rectangle.百分比扩展(percent expand) - INT, 0–200, default 0. Extra canvas beyond the bounding box, as a percentage of content size.最小扩展像素(minimum expand pixels) - INT, 0–100, default 0. A floor on how much padding you keep.
Outputs. Three:
合并Alpha图片(merged alpha image) - the crop composited with a transparency derived from the mask, so the subject sits on a real alpha background.裁剪后图片(cropped image) - the canvas-cropped image, content untouched.透明蒙版(transparent mask) - the mask cropped to match.
Which output you use depends on the job: alpha-composited if you're about to drop it onto a new background, plain crop if you just wanted the padding gone.
Gotchas. The white-background convention matters. If your mask is the opposite (black background, white subject - the default for many ComfyUI mask nodes), the node reads the background as the content and you'll get a nonsensical crop. Flip it upstream (ComfyUI's InvertMask, or any invert node) before feeding it here. Also: with square output on and a very wide or tall source, you can end up adding canvas rather than removing it - square mode normalizes to the longer side, which for a panoramic source means the square is bigger than the content.
Install. Part of KimNodes (wjl0313's 🍒 toolbox on the Comfy registry). ComfyUI Manager → search "ComfyUI_KimNodes", or:
cd ComfyUI/custom_nodes
git clone https://github.com/wjl0313/ComfyUI_KimNodes
then restart. PIL/numpy/torch only - no models to download.
Troubleshooting. If the crop ignores your mask entirely, check polarity first (see above). If you get a 1×1 transparent image back, the node found no non-zero mask region at all - the mask is empty or all one value. And if edges look clipped despite padding, remember the padding params are expansion; set both to something small like 10 if you want a little margin rather than a hairline-tight crop.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| 图片 | IMAGE | — | |
| 蒙版 | MASK | — | |
| 正方形输出 | BOOLEAN | true | — |
| 百分比扩展 | INT | 00–200 | — |
| 最小扩展像素 | INT | 00–100 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| 合并Alpha图片 | IMAGE | — |
| 裁剪后图片 | IMAGE | — |
| 透明蒙版 | MASK | — |