RonLayers/TrimBg: RonLayersTrimBgUltraV2
It won't remove your background — it trims what's left
- image
- mask
- croped_image
- croped_mask
- crop_box
- box_preview
The name says "AutoTrimBG" and the README says it "automatically cleans up the background of your images." Neither is quite true, and knowing that is half the battle. This node detects nothing and removes nothing. You hand it an image and a mask - the mask is the whole show - and it crops both down to a tight box around your subject, slicing off the dead space. The actual background removal is still on you, done upstream with BiRefNet, rembg, InSPyReNet, or whatever your mask-maker of choice is. What this adds is the cleanup after the cutout: taking a full-frame image with a subject floating in a sea of empty pixels and turning it into a tight, subject-only canvas.
Why bother? Because a lot of downstream steps waste their effort on that margin. Relight with IC-Light and it lights the whole frame, not just the subject. Upscale 2x and you double the empty canvas along with the subject. Composite onto a new background and you're dragging a giant transparent file around. A tight crop-to-mask means every pixel your upscaler or relighter touches is subject.
How it works
Under the hood it's about twenty lines of PIL - no model, no weights, no network, no API key. It composites your image over a transparent layer using your mask, calls getbbox() to find the smallest rectangle containing any non-transparent pixel, expands that rectangle by your padding (clamped to the image edges), and crops. The output is re-composited over transparency, so the background is gone from the crop too, not just trimmed.
Two edge cases worth knowing. If your mask is empty, there's no box to find - the node passes image and mask through untouched and crop_box comes back as None. And if you feed a batched mask with more than one frame, it silently keeps only the first (it does log a warning, but easy to miss in the console).
Inputs and outputs that matter
Three inputs, and only one you'll actually touch:
image(IMAGE) - your cutout source, before cropping.mask(MASK) - the alpha/segmentation mask that defines the subject. This is the one to get right; the crop is only as good as the mask.padding(INT, default 0, range 0–1000) - extra margin around the subject. Zero gives a hair-tight crop that can feel cramped once you composite; 10–50 is usually a saner start.
Four outputs:
croped_image(IMAGE) - the RGBA crop, subject on transparency. Yes, it's misspelled in the schema; that's the real name, use it as-is.croped_mask(MASK) - the matching crop of your mask.crop_box(BOX) - the(x1, y1, x2, y2)rectangle it cropped to, if you need the numbers downstream.box_preview(IMAGE) - your mask with a green box drawn over the crop region. Wire it to a preview node once to sanity-check the box lands where you think.
From there, croped_image feeds straight into your compositor, relight, or upscaler.
Installing it
Use ComfyUI Manager: search "ComfyUI-AutoTrimBG", hit install, restart ComfyUI. Or clone it manually:
cd ComfyUI/custom_nodes
git clone https://github.com/fexploit/ComfyUI-AutoTrimBG
Then restart. No models to download, no CUDA dependencies - it's pure PIL/numpy/torch. You'll find the node under the RonLayers/TrimBg category in the menu, as "RonLayers/TrimBg: RonLayersTrimBgUltraV2".
Gotchas
The README is the biggest trap, and it's bad enough to warrant a warning. It's an AI-generated stub: the clone URL points at yourusername, it calls the pack "ComfyUI-AutoCropBgTrim" (the repo is ComfyUI-AutoTrimBG), and its "usage example" is nonsense - torch.load on image files, .save() called on tensors. Don't follow its install steps either. The pinned requirements.txt wants torch 1.10.0, numpy 1.21.2 and Pillow 8.4.0, all 2021 versions; running pip install -r requirements.txt in a modern ComfyUI venv would try to downgrade your torch and take half your other nodes down with it. The node only needs Pillow, numpy and torch, which any ComfyUI install already has. Skip the requirements file entirely.
Second gotcha: croped_image is RGBA, and some downstream nodes silently drop the alpha channel - then you've got a black or white square where your transparency was. If the cutout looks wrong further down the graph, check whether the node in between keeps alpha.
And the honest verdict: this is a thin utility. It does exactly one job, with zero dependencies and nothing to rot. If you need a mask-driven crop that ComfyUI's core nodes make you assemble from three separate steps, that's a genuine timesaver. If you were hoping for a one-click background remover, you'll be disappointed - that's the ecosystem's unsolved frontier, and it lives in the segmentation model upstream of this node, not here.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — | |
| padding | INT | 00–1000 | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| croped_image | IMAGE | — |
| croped_mask | MASK | — |
| crop_box | BOX | — |
| box_preview | IMAGE | — |