Nodes/ComfyUI_BadgerTools/TrimTransparentEdges-badger
ComfyUI Node

TrimTransparentEdges-badger

Auto-trim the dead space off your transparent cutouts

By AbyssBadger0·Created 3 years ago·Updated 2 years ago· 8
TrimTransparentEdges-badger
  • image
  • IMAGE

Background-removal models are great at cutting a subject out and terrible about caring how much transparent padding they leave around it. That invisible border shifts alignment, bloats upscales, and generally makes compositing a pain. TrimTransparentEdges-badger is the cleanup step: it finds the tightest bounding box that contains every non-transparent pixel and crops to it.

The mechanism is gloriously unglamorous. It converts the image to RGBA, iterates over every pixel, and collects the coordinates of any pixel whose alpha channel isn't zero. Then it takes the min and max of those x and y coordinates, crops with Pillow's Image.crop(), and returns the result. No machine learning, no heuristics - just "where does the visible stuff actually start and end." It also runs a memory cleanup pass after cropping, which is a nice touch given how much RAM image workflows can chew.

The schema is a single pair:

  • image - an IMAGE tensor in.
  • image - the cropped IMAGE out.

So the whole node is a one-in, one-out image filter, which makes it trivial to drop into a chain: BiRefNet or rembg cutout → this node → composite / upscale / save.

Three gotchas matter in practice. First, it only looks at the alpha channel. If your image has no transparency (a fully opaque PNG or a JPG), nothing gets trimmed - there are no non-transparent edges to find, so the image comes back essentially unchanged. Don't expect it to autocrop opaque images; that's a different tool. Second, a single stray pixel of semi-transparency at the corner will expand the crop box to include it - if your cutout has a faint halo, the trim will hug the halo, not the subject. Clean the alpha first if you want a truly tight box. Third, if the image is fully transparent, it raises a ValueError and the workflow fails - worth knowing before you feed it a blank cutout on an automation loop.

Installation is the standard two-step:

cd ComfyUI/custom_nodes
git clone https://github.com/AbyssYuan0/ComfyUI_BadgerTools

or search ComfyUI_BadgerTools in ComfyUI Manager, then restart. It's under the badger category, has no heavy dependencies, and needs no model downloads - it's pure Pillow. For anyone doing sprite work, sticker cuts, or any compositing pipeline with alpha, it's the kind of tiny node that quietly saves you an hour of manual cropping per batch. Not a headline feature, just a dependable one.

Categorybadger

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (1)

NameTypeDescription
IMAGEIMAGE