TrimBG
Auto-crop every image to its subject's tight bounding box
- images
- image
Take an image with a transparent background, and you usually want one thing next: the subject cropped tight, no wasted canvas. TrimBG does that automatically - it finds the bounding box of the non-transparent pixels and crops to it, across a whole batch at once. It's the classic "background removal → auto-crop" finishing move, minus the manual cropping.
It's from comfyui-missed-tool, ifmylove2011's small utilities pack. The README pitches exactly the workflow you'd guess: remove the background first, then TrimBG trims the result. It plays especially well with BiRefNet, the current default background remover (and the one ComfyUI now ships in core), because BiRefNet hands you RGBA images where the subject is genuinely separated - the perfect input for this.
How it works
For each image in the batch, TrimBG works out where the subject is, then crops:
- If the image is RGBA, it uses the alpha channel directly.
- If it's RGB with no alpha, it falls back to the luminance (grayscale) channel as a stand-in for alpha - bright pixels count as opaque.
- It computes the bounding box of whatever remains, crops to it, and that's your output image.
One thing to know: the plain TrimBG node has exactly one input, images (IMAGE), and runs with fixed defaults. The pack also ships TrimBG Advanced, which adds a mask input, padding (negative padding can shave into the subject), an alpha_thresold for cleaning noisy transparency, and fill_rbg - a hex color that replaces transparent pixels after cropping, turning your cutout into a tight square on a solid background.
The output, image, is the batch of tight crops.
Installing it
Via ComfyUI Manager, search comfyui-missed-tool, or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/ifmylove2011/comfyui-missing-tool
cd comfyui-missing-tool
pip install -r requirements.txt
Restart ComfyUI. Dependencies are torch, numpy, Pillow - all stock - and there are no model downloads. TrimBG shows up under the "img-process/TrimBG" category in the menu (the rest of the pack lives under "missed-tool"). The README's clone URL spells the repo "comfyui-missed-tool"; the actual repo is "comfyui-missing-tool" and GitHub redirects either.
Where people get burned
- RGB input means luminance guessing. If you feed plain RGB images, TrimBG decides "opaque" from brightness - a dark subject on a bright background crops wrong, and a mid-gray subject can vanish entirely. This is the trap. Feed it RGBA (from BiRefNet, or from this pack's LoadImageA with
rgba_modeon) and it becomes predictable. - The plain node is stripped down. No padding, no mask, no fill. If you need any of those, that's what TrimBG Advanced is for - the basic node is deliberately dumb.
- It crops, it doesn't resize. You get tight crops, not uniform squares. If your next step needs consistent dimensions, follow up with a scale/pad node.
The README's suggested pairing - Inspire Pack's "Load Image List From Dir" feeding a folder of images, TrimBG cropping each - turns bulk cutout cleanup into a one-run batch job. For icon extraction, card making, or dataset prep, that's a genuinely handy thing to have sitting in the graph.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |