Light-Tool: Bounding Box Cropping
Auto-crop to the transparent subject — dead space, gone
- image
- image
Light-Tool: BoundingBoxCropping looks at an image with transparency, finds the tightest rectangle that contains all the opaque pixels, and crops to exactly that. All the empty transparent canvas around your subject - the dead space left behind by a background removal, a generated cutout, or a padded composite - gets trimmed in one step. It's the "tighten the crop to the subject" node.
If you've ever cut out a subject and ended up with a 2048×2048 PNG where the actual character occupies a small corner, you know exactly why this exists. Downstream nodes that resize or re-composite on that canvas are wasting pixels and often producing awkwardly-centered results. This node fixes the canvas.
How it works
The mechanism is about as robust as it gets for this job. Each image is converted to RGBA, and the alpha channel is handed to OpenCV's boundingRect, which computes the smallest axis-aligned rectangle covering all non-zero alpha pixels. That rectangle becomes the crop. It then re-stacks the result, preserving the batch.
Because it keys off alpha rather than pixel brightness, it's unaffected by a dark or busy subject - what matters is where the opaque content is. Fully transparent pixels anywhere get trimmed. The output keeps its alpha channel, so you can hand the tightened cutout straight to a save or a compositing node.
Inputs and output
The whole interface is a single image input. No margins, no threshold, no configuration - drop it in and it does the obvious thing. Output is one image, cropped to the opaque bounding box.
The lack of a padding option is worth noting: the crop is tight. Subject edges land right at the canvas edge, which can look cramped if you then add a background or composite it. In practice, people chain this with AddBackgroundV2 and use its margin inputs to add breathing room back - tight crop, then re-pad to taste. That pairing is probably the most common use of this node in real workflows.
Where it fits
This belongs in the transparency pipeline right after you have a cutout:
- Background removal produces an image with a subject floating in transparent space.
- BoundingBoxCropping trims to the subject.
- Resize or composite with a clean canvas,
AddBackgroundto flatten.
It also plays nicely with ImageMaskApply - turn a mask into a cutout, then tighten it. And because it's batch-safe, a whole folder of removed-background images gets uniformly trimmed in one pass.
Gotchas
The crop is driven entirely by alpha, so an image with no transparency is a no-op - there's nothing to trim and you get the original back. And if your subject has a transparent hole in the middle (a donut, a frame, a gap between two objects), the bounding box spans the whole thing; this node doesn't split objects or crop each one separately. For per-object crops, you'd need a detection step first.
Standard install: ComfyUI Manager → search ComfyUI-Light-Tool, or clone into custom_nodes, pip install -r requirements.txt, restart. OpenCV is already in the pack's dependency list, so nothing extra to fetch.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |