Nodes/ComfyUI-Minitools/Crop Transparent Edges 👻
ComfyUI Node

Crop Transparent Edges 👻

Get Your Cutout Out of All That Empty Space

By lepiai·Created 2 years ago·Updated 3 days ago· 8
Crop Transparent Edges 👻
  • image
  • IMAGE

The thing nobody warns you about after background removal

You cut out a subject with BiRefNet or whatever you're using, and now it's floating in the middle of a big transparent canvas. That dead space is fine on screen, but it's a nuisance downstream: every crop is larger than it needs to be, compositing gets fiddly, and downstream image processors waste pixels on emptiness. Crop Transparent Edges fixes that automatically - you feed it an RGBA image and it crops down to the bounding box of everything that isn't transparent. It's auto-trim for PNGs.

Core ComfyUI's Crop Image node needs explicit coordinates. This node finds the box itself, which is exactly what you want in a pipeline where you don't know where the subject landed until after generation. It pairs naturally with an alpha-preserving VAE decode or a background-removal stage in the same graph.

How it works

The mechanism is small and honest. The node takes the first frame of your image tensor, converts it to a PIL RGBA image, and calls PIL's built-in getbbox(), which returns the smallest rectangle containing every non-zero pixel. It crops with that box and hands the result back as an IMAGE. A few lines of PIL doing exactly what it says - there's no detection model, nothing to download, no API call.

The inputs that matter

There's one input and one output, so this is the whole manual:

  • image (IMAGE) - an RGBA image with transparent regions you want trimmed. That's it.
  • Output: IMAGE - the same image cropped to the opaque content.

Where people get burned

  • It refuses 3-channel input. Feed it an RGB image and it raises Image must have 4 channels (RGBA). Make sure you're cropping after something that preserved alpha, not after a stage that dropped it.
  • It only processes the first frame of a batch (image[0]). If you're trimming a batch of cutouts, you'd have to loop or process each one individually.
  • getbbox() counts any non-zero channel as content. For a clean cutout where the RGB under transparent regions is black, that's exactly right. But if your cutout has junk color values hiding underneath zero alpha, the crop can include a sliver of unwanted edge. Keep your alpha clean and this never bites.

Installing it

This ships in the ComfyUI-Minitools pack, a small personal toolkit (category "MiniTools", ghost 👻 in the display names) from lepi ai. No model downloads - this node is pure Python.

cd ComfyUI/custom_nodes
git clone https://github.com/lepiai/ComfyUI-Minitools

then restart ComfyUI. Or use ComfyUI Manager → Custom Nodes Manager → search "ComfyUI-Minitools" → Install → Restart (it's on the Comfy Registry).

One pack-wide gotcha worth knowing even though this node is offline: the pack's requirements.txt pins openai, Pillow, numpy and requests, and __init__.py imports the LLM node at load time. If openai isn't installed, the whole pack fails to import and none of the seven nodes show up - including this one. Manager installs requirements for you; if you cloned manually, run pip install -r requirements.txt in ComfyUI's Python environment first.

CategoryMiniTools

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (1)

NameTypeDescription
IMAGEIMAGE