Intelligent AutoCrop
Strip the Alamy border before it becomes your subject
- image
- crop_config
- image
- trim_left
- trim_top
- trim_right
- trim_bottom
- detected
What it's for
If you work with stock or host-sourced photos, you know the thing: a black or white frame around the picture, sometimes with a caption strip of lettering welded to the bottom edge. Feed that straight into a subject-mask segmenter and "the subject" now includes the frame, which throws off your framing, your resolution tier and your crop. So this runs first.
Intelligent AutoCrop removes solid borders and text-bearing dark footers - the Alamy-style hosting frame is the explicit use case, though detection doesn't depend on the brand, a font, or OCR. It crops and does nothing else: no resize, no interpolation, no colour change, no padding. Subject framing, aspect ratios and editor resolution belong to Smart Photo Prepare, which is a separate stage for a reason.
How it works
It reads the first, AUTOCROP · SOLID BORDER REMOVAL section of the Input & Crop Config bundle and looks at each edge independently for a solid run. A footer has a stricter test than a border: it must touch the bottom edge, have a consistent dark background, contain small aligned bright components consistent with lettering, and have a contrasting upper boundary - and its total height must be under the bottom 20% search region. It checks the whole proposed footer, so it won't slice through lettering, and it strips at most one footer. Up to four passes handle nested frames. A plain black border needs no footer logic at all.
Your border tolerance lives in the config (autocrop_fuzz_tolerance for how much colour variation counts as solid, autocrop_edge_uniformity for the fraction of the edge that must match). What the node adds locally is border_policy:
- Conservative (the default) requires ≥98.5% matching coverage, caps the colour tolerance at 0.12, and requires a stable edge colour plus broad, contrasting photo-boundary evidence.
- Configured tolerances uses your numbers literally, no safeguards. Useful for comparison or genuinely noisy borders - inspect the result.
A studio shot of a person against a seamless white background is exactly the case this gets wrong, and the author says so: identical solid backgrounds and added borders are visually ambiguous. Conservative mode errs toward leaving uncertain pixels alone, which is the right failure direction.
Inputs and outputs
image and crop_config are required; border_policy is the one optional dropdown. Six outputs, and order matters if you're rewiring an old workflow: image, then trim_left, trim_top, trim_right, trim_bottom, then detected. detected is true only when a nonzero crop was actually applied after padding and batch checks.
The trim integers are the practical half. This node doesn't touch masks, so if you already built a subject or protected-region mask, crop it with the same margins using Crop by Margins (Mask) - and do that on the post-cleanup image in the first place, since masks generated before border removal include the border.
Load Image + Source Info → Intelligent AutoCrop → segmenter (subject / head mask) → Smart Photo Prepare
Two details that bite on batches: for a real tensor batch, every member is analysed and the minimum safe trim is applied to all of them, so a single borderless image in the batch can prevent cropping entirely. And with both autocrop_detect_borders and autocrop_strip_bottom_banner off, the node returns the input tensor unchanged - a good way to sanity-check that it's actually the thing changing your picture.
RGBA is passed through untouched, so composite transparency in the loader before it arrives. And no, it is not a watermark remover; fine hairline watermarks inside the photo are not borders.
Install
ComfyUI Manager → search PortraitUtils (publisher heyburns, GPLv3), or:
cd ComfyUI/custom_nodes
git clone https://github.com/heyburns/PortraitUtils
/path/to/ComfyUI/venv/bin/python -m pip install -r PortraitUtils/requirements.txt
Border detection runs through OpenCV, so that wheel matters - opencv-python-headless>=4.10.0.84, and install only one OpenCV variant in your environment or you'll get namespace confusion. Restart the ComfyUI server after installing.
Where people get burned
The defaults are conservative, which means some low-contrast, damaged or densely-branded layouts simply won't get cropped. That's not a failure of the node, it's the trade it chose. Re-run in Configured tolerances if you want to see the difference, then tweak the config values, not the node.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| crop_config | PORTRAIT_CROP_CONFIG_V2 | — | |
| border_policyopt | COMBO | Conservative | Conservative: require 98.5% solid edge coverage and cap color tolerance at 0.12. Configured tolerances: use the config thresholds literally; inspect crops carefully. Both require a bounded border and a contrasting content boundary. |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| trim_left | INT | — |
| trim_top | INT | — |
| trim_right | INT | — |
| trim_bottom | INT | — |
| detected | BOOLEAN | — |