🔄

Image Border Trimmer

Auto-trim whitespace or solid-colour borders from an image

GET 10 credits /v1/image/trim
curl "https://image.toolkitapi.io/v1/image/trim?url=https://toolkitapi.io/static/samples/sample-image.png&tolerance=15"
import httpx

resp = httpx.get(
    "https://image.toolkitapi.io/v1/image/trim?url=https://toolkitapi.io/static/samples/sample-image.png&tolerance=15",
)
print(resp.json())
const resp = await fetch("https://image.toolkitapi.io/v1/image/trim?url=https://toolkitapi.io/static/samples/sample-image.png&tolerance=15", {
});
const data = await resp.json();
console.log(data);
# See curl example
Response 200 OK
{
  "image": "iVBORw0KGgoAAAANSUhEUg...(base64 data)...",
  "format": "png",
  "original_size": {"width": 1200, "height": 1200},
  "new_size": {"width": 980, "height": 950},
  "trimmed": true
}

Try It Live

Live Demo

Description

Auto-trim whitespace or solid-colour borders from an image

How to Use

1

1. Provide the source image via the `url` query parameter.

2

2. Set `tolerance` (0–255) to control how strictly the border colour is matched. Higher values trim more aggressively.

3

3. The trimmed image is returned along with original and new dimensions.

4

4. Check the `trimmed` field — if false, no border was detected.

About This Tool

Use the Image Border Trimmer to automatically detect and remove uniform borders around an image. It compares each pixel to the top-left corner pixel colour and trims any matching border area, with a configurable colour tolerance.

This is particularly useful for product photography (removing white backgrounds), scanned documents (removing scanner borders), and cleaning up screenshots or exported images with unnecessary padding.

Why Use This Tool

Frequently Asked Questions

How is the border colour determined?
The colour of the top-left pixel (0, 0) is used as the reference. Any contiguous border area matching this colour within the tolerance is trimmed.
What tolerance should I use?
Tolerance 0 requires an exact colour match. Use 5–15 for slightly uneven backgrounds (e.g. scanned paper). Use 30+ for gradients or noisy borders.
What happens if the entire image is one colour?
If no content boundary is detected, the original image is returned unchanged and `trimmed` is set to false.

Start using Image Border Trimmer now

Get your free API key and make your first request in under a minute.