Nodes/ComfyUI-crop-alpha/Fast Alpha Cropper
ComfyUI Node

Fast Alpha Cropper

Trim the transparent dead space off any RGBA cutout

By dzqdzq·Created 2 years ago·Updated 2 years ago· 4
Fast Alpha Cropper
  • image
  • image
  • mask
padding0

Ever generate a transparent image - LayerDiffusion-style, or a cutout out of a background remover in RGBA mode - and get back a full 1024×1024 canvas with your subject floating somewhere in the middle? FastAlphaCropper is the answer to that: it finds the bounding box of every non-transparent pixel and crops the image down to exactly that, dead space gone. The "Fast" isn't marketing, it's a pure tensor operation - no model, no download, no GPU muscle.

This is one of those utility nodes you don't think about until you need it, and then you need it constantly. The moment you feed an untrimmed cutout to an upscaler, a detailer, or a compositing pass, you're spending resolution and VRAM on empty transparent pixels, and your aspect ratio is whatever the generator felt like. Cropping to the subject first keeps every downstream op pointed at the thing you actually care about.

How it works

Read the source and it's refreshingly simple. For each image in the batch it grabs the alpha channel (channel 3), builds a mask where alpha > 0.01, finds the first and last non-zero row and column, pads the box by your padding value, clamps it to the image bounds, and slices. Two edge behaviors from the code are worth knowing before they bite you:

  • It assumes RGBA. Feed it a plain RGB image and the img[..., 3] alpha lookup throws, because there is no channel 3. It's designed for the output of transparent-generation or RGBA background-removal paths.
  • Fully transparent frames pass through untouched - you get the original image back plus a zeroed-out mask. Fine if you're batch-processing and some frames are empty, a trap if you assumed everything gets trimmed.
  • The cropped result keeps all four channels, alpha included. It doesn't strip the channel, which is what you want for compositing, but a downstream node expecting pure RGB may silently drop the alpha. That "RGBA gets dropped somewhere in the pipeline" problem is real across ComfyUI - worth checking once if your export comes out opaque.

The inputs and outputs that matter

There are only two inputs, and you'll set one:

  • image (IMAGE) - your RGBA tensor. Batch-aware; it loops every frame and crops each individually.
  • padding (INT, default 0, max 500) - adds breathing room around the bounding box. Default 0 crops tight against the subject, which looks great until your mask has soft or semi-transparent edges. A small pad (4–16) is usually the right call.

Outputs: image - the cropped RGBA - and mask, the cropped alpha as a proper MASK tensor. They're the same region by construction, so you can wire the mask straight into a compositing or overlay step and everything lines up, which is more than some alpha tools give you.

Install

It's a two-line affair with zero baggage - the pyproject.toml lists no dependencies, and the code only touches torch, PIL, and torchvision, all of which ship with ComfyUI's Python environment. No model files, no keys, nothing to download beyond the repo itself.

Via ComfyUI Manager, search "ComfyUI-crop-alpha" and install. Or by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/dzqdzq/ComfyUI-crop-alpha

Then restart ComfyUI. It appears in the image/processing category.

Verdict

If you already run WAS Node Suite or ComfyUI-essentials you can patch together a similar trim with their crop nodes, but those don't hand you the aligned mask, and the alpha-awareness here is the whole point. For the narrow job it does - trim the transparent border, keep it RGBA, get a matching mask - FastAlphaCropper is hard to beat. Small, unglamorous, and exactly the tool you want when your cutout is 70% empty canvas. It pairs naturally with its sibling ShrinkImage in the same pack if the result is still bigger than you need.

Categoryimage/processing

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
paddingINT00–500

Outputs (2)

NameTypeDescription
imageIMAGE
maskMASK