Nodes/ComfyUI-ImageAlphaCrop/Image Alpha Crop
ComfyUI Node

Image Alpha Crop

Image Alpha Crop — the dead-space trimmer for transparent cutouts

By swan7-py·Created 10 months ago·Updated 10 months ago· 4
Image Alpha Crop
  • images
  • cropped_images
padding0
alpha_threshold0.01

The name is the whole job description. You cut a logo out with BiRefNet or rembg, or generated it transparent with something like LayerDiffusion, and the result is your content floating in a big invisible margin of empty pixels. Image Alpha Crop finds where the content actually starts and trims every transparent border away - and, unlike a lot of the pipeline, it hands you the crop still carrying its alpha channel.

That last part is the reason this node exists, not a footnote. ComfyUI's native load/save path thinks in RGB plus a separate MASK tensor, and in practice a lot of intermediate nodes silently drop the 4th channel on the floor. This pack (swan7-py's ComfyUI-ImageAlphaCrop) is a small RGBA end-to-end kit, and this is its simplest node: crop the transparent frame, keep the transparency.

How it works

No models, no VRAM, no downloads - it's plain tensor math. For each input image the node looks at the alpha channel and marks every pixel whose alpha is above alpha_threshold as visible. Then it takes the bounding box of all visible pixels and crops to it. Because it's a bounding box over all visible pixels, a logo with a hollow middle isn't a problem - the box just spans the hole. It also adds padding around the crop if you want breathing room.

Two defaults worth knowing. alpha_threshold sits at 0.01, which is about 2.5 on a 0–255 scale - anything fainter than that counts as transparent and gets trimmed. Lower it and you keep more faint, semi-transparent edge pixels; raise it and you cut tighter but risk eating soft antialiased edges. padding is 0–100 pixels, default 0.

If the input has no alpha channel at all, the node appends an opaque one - so feeding it a plain RGB image won't crash, it just finds nothing to trim and hands back an opaque crop.

The inputs and output

Only three inputs matter here:

  • images - your transparent IMAGE tensor (batch supported).
  • padding - extra pixels kept around the content after cropping.
  • alpha_threshold - how faint a pixel must be before it counts as transparent.

The single output, cropped_images, is an RGBA IMAGE tensor, one frame per input. Wire it straight into the pack's Save Image (RGBA) node - that's the pair this pack is built around: crop the dead space, then save a PNG that actually keeps the transparency.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/swan7-py/ComfyUI-ImageAlphaCrop

then restart ComfyUI. Or search "ImageAlphaCrop" in ComfyUI Manager - it's on the Comfy Registry, so it's a one-click install. There are no extra dependencies and no model files: the whole pack runs on numpy, torch, and Pillow, all of which ComfyUI already ships.

Gotchas

The batch behavior is the one thing that bites people. The node crops every frame in the batch to its own bounding box, then stitches them together with a batch concatenation - which requires every frame to come out the same size. Two different-sized logos in one batch = tensor shape mismatch error. If you're processing mixed content, run one image per batch (or use the Advanced variant with a fixed target size).

A fully transparent input returns the original image unchanged rather than erroring, which is graceful but also easy to misread as a bug when you're debugging. And remember this node resizes nothing - it only crops. If you need a fixed output size, letterboxing, or the "crop one image using another image's alpha" trick, that's the Advanced node's job.

CategorySwan

Inputs (3)

NameTypeDefaultDescription
imagesIMAGE
paddingINT00–100
alpha_thresholdFLOAT0.010–1

Outputs (1)

NameTypeDescription
cropped_imagesIMAGE