💀Image Crop To Fit
Trim the transparent dead space off a cutout
- image
- cropped_image
Cutouts carry baggage. When you remove a background, you usually end up with a small subject floating in a large transparent canvas, and every downstream node has to process that wasted space - upscalers, compositors, tiling, whatever comes next. 💀Image Crop To Fit from the S4Tool-Image pack does the obvious thing nobody else bothers doing for you: it trims the image down to the bounding box of the non-transparent pixels. One input, one output, no settings.
The mechanism is exactly what you'd hope: the node converts the image to RGBA, scans the alpha channel for the first and last opaque pixels in both dimensions, crops to that rectangle, and returns the result. If the image is entirely transparent, it returns a 1×1 transparent pixel rather than crashing - a small detail, but the kind of edge case that marks a node as having been actually used. The output keeps its transparency, so the crop doesn't flatten anything.
Input and output
image- the IMAGE to trim. It's expected to have transparency; the crop is driven entirely by the alpha channel.
Output: cropped_image (IMAGE), now sized to the content with transparent borders removed.
Where it fits in a workflow: right after a background-removal node (the pack's own 💀Image RMBG works great upstream), or after a segmentation cutout from 💀Image SAM / SAM2. Feed the trimmed result into a compositor, an upscaler, or 💀Image Tiling Pattern and you're not paying for empty pixels. It's also a tidy finish step before saving a PNG you plan to drop into another tool.
Install
Standard S4Tool-Image pack install:
cd ComfyUI/custom_nodes/
git clone https://github.com/S4MUEL-404/ComfyUI-S4Tool-Image.git
pip install -r ComfyUI-S4Tool-Image/requirements.txt
Or ComfyUI Manager → search "S4Tool-Image" → Install → restart. Pure Pillow/numpy, nothing to download.
Gotchas
- Only transparent borders get trimmed - if your image has a colored (not transparent) background, the crop finds nothing to remove. The node is deliberately alpha-driven, so make sure what you feed it is actually RGBA.
- Fully transparent input gives a 1×1 result - that's the safe fallback, not a bug. Don't build a workflow that assumes content exists without checking.
- It's a trim, not a resize - "crop to fit" here means "fit the content," not "fit a target size." For forcing an image into specific dimensions, you want an actual resize/crop node; this one just removes dead space.
Boring, deterministic, and genuinely useful - the kind of glue node that makes a pipeline feel finished instead of held together with transparent pixels.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| cropped_image | IMAGE | — |