Auto Crop Image
Say goodbye to the sea of transparent padding
- image
- mask
- IMAGE
Every background-removal workflow ends the same way: you cut your subject out with BiRefNet or rembg, and it floats in the middle of a 1024×1024 canvas with a mile of fully transparent pixels around it. Then your upscaler happily spends all its effort on emptiness, your VAE wastes tokens on nothing, and compositing gets fiddly because your crop is never where you expect it. Auto Crop Image is the tiny cleanup step that fixes that: it finds the tightest rectangle around the non-transparent pixels and crops to it. One input in, one IMAGE out, zero configuration.
It ships in the same pack as Normalize Image With Rectangle, and honestly the two are opposite halves of the same habit - one trims dead space, the other adds it back on a fixed canvas. Both are about getting your cutouts into a predictable shape before the next stage of the graph.
How it works
For each image in the batch, the node looks at the alpha channel, finds the smallest rectangle that contains every pixel with alpha above zero, and crops to it. No AI, no heuristics - just a bounding box over non-transparent pixels. A few details from the source worth knowing:
- RGBA images use the alpha channel to find the box.
- Plain RGB images have no alpha, so the node treats every pixel as opaque and returns the image basically untouched. If your crop "does nothing," this is why.
- The optional
maskinput overrides alpha entirely. Pass a SAM or segmentation mask and it crops to that instead - handy when you've got a mask but no alpha channel.
Two behaviors to file away. If the whole image is transparent, the node leaves it as-is rather than collapsing it to nothing - the right call, even if it surprised me the first time. And on a batch, each image gets its own individual crop, then everything is padded back to the largest cropped size so the output stays one rectangular tensor. That means a batch's crops won't all be tight - for a single image you get the exact box, for a batch you get the tightest box the batch can share.
Where it fits
Stick it right after your background-removal node and before anything that touches resolution - upscaling, VAE encode, or compositing onto a scene. The KB's background-removal essay is worth reading for the wider picture, but the short version is that cutouts come out of the segmentation model on a big padded canvas, and this is the step that reclaims it. Also useful before you paste a LayerDiffusion transparency output into an img2img pass, so the model isn't staring at empty transparent corners.
Gotchas
The crop threshold is alpha > 0, which is stricter than you might want. Faint semi-transparent dust or matting residue around your subject will widen the bounding box, so a dirty mask gives you a sloppy crop. A tight mask gives a tight crop. Don't expect it to clean up edges - it only trims outer dead space.
Install
The pack is called ComfyUI-HM-Tools on GitHub. Easiest path: ComfyUI Manager → search "HM-Tools" → install, then restart ComfyUI. Or clone it manually:
cd ComfyUI/custom_nodes
git clone https://github.com/hiderminer/ComfyUI-HM-Utilities
# restart ComfyUI
Nice part: there's no requirements.txt and no model downloads. It's pure torch/numpy, which ComfyUI already ships. That also means it can't break your Python environment with a version conflict - genuinely rare for a custom node, so it gets points for that. It's GPL-3.0 licensed, a small personal utility pack from hiderminer (© 2025), and obscure enough that I couldn't find a single Reddit thread mentioning it - don't expect a tutorial ecosystem, but you won't need one.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| maskopt | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |