ImageCropByAlpha ♾️Mixlab
Crop tight to the transparent subject and get its box back
- image
- RGBA
- IMAGE
- MASK
- AREA_MASK
- x
- y
- width
- height
You just ran background removal and now you've got a subject floating in a big transparent frame, with acres of empty pixels around it. ImageCropByAlpha trims that down to the tight bounding box of the actual subject - the non-transparent region - and, crucially, also hands you back where that box was. That last part is what makes it more than a cropper. When you want to cut something out, process it at full resolution, and later paste it back exactly where it came from, you need the coordinates. This node gives you the crop and the coordinates in one shot.
It lives in shadowcz007's mixlab pack, in the same family as the pack's layers/composite nodes. The intended flow is background-removal → crop-to-subject → do work → composite back, and this node is the "crop-to-subject" step that also remembers the geometry for the eventual paste.
How it works
It reads the alpha channel of an RGBA input, finds the bounds of everything that isn't fully transparent, and crops to that rectangle. Alongside the cropped RGB it produces the mask of the subject, a mask of the cropped area, and the four numbers that describe the box: x, y, width, height. Feed those numbers into a composite/paste node later and the subject drops back into its original position at its original size. Because the outputs are lists, it handles the case where there's more than one region to pull out rather than assuming a single blob.
The inputs and outputs that matter
Inputs (both required):
image(IMAGE) - the picture.RGBA(RGBA) - the transparency-carrying input. This is a mixlab-specific type, so it wants an RGBA source from within the pack (itsTransparentImage/ rembg-style nodes) rather than a plain IMAGE. That coupling is the one thing to get right - the alpha is what the whole node reads.
Outputs, all as lists:
IMAGE- the tightly cropped picture.MASK- the subject's mask.AREA_MASK- a mask of the cropped region.x,y,width,height(INT) - the bounding box. Keep these; they're how you paste it back.
The mask and the coordinates are what set this apart from a generic crop node - most croppers throw the position away.
How to install it
ComfyUI Manager: search comfyui-mixlab-nodes, install, restart. Or clone it manually:
cd ComfyUI/custom_nodes
git clone https://github.com/shadowcz007/comfyui-mixlab-nodes.git
then pip install -r requirements.txt (or install.bat on the Windows portable build) and restart. If you're going to feed this from the pack's own background-removal node, note that rembg needs its models downloaded into models/rembg - that's the upstream step that produces the transparency this node reads.
Common issues & troubleshooting
It won't connect to my image. The RGBA input isn't a plain IMAGE - it's the pack's own RGBA type. If ComfyUI refuses the wire, you're trying to feed it a standard image without an alpha channel. Route it through the pack's transparent-image / rembg node first so there's a real alpha to crop against.
The crop is the full frame / nothing got trimmed. That means the alpha isn't actually transparent anywhere - every pixel counts as subject, so the bounding box is the whole image. Check your background removal actually produced transparency and didn't just paint a solid background. A weak matte with faint non-zero alpha everywhere gives the same too-loose result.
Paste-back lands in the wrong spot. You're probably feeding the composite node the wrong reference size. The x/y/width/height are relative to the original canvas - paste back onto a canvas of that same size, not onto the cropped image.
Multiple outputs when I expected one. The outputs are lists on purpose. If your removal left several disconnected islands of subject, you can get more than one region back. Collapse them upstream (clean the mask) if you only want a single crop.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| RGBA | RGBA | — |
Outputs (7)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |
| AREA_MASK | MASK | — |
| x | INT | — |
| y | INT | — |
| width | INT | — |
| height | INT | — |