🔄

Image Crop

Crop an image by coordinates, center-gravity, or smart square

GET 10 credits /v1/image/crop
curl "https://image.toolkitapi.io/v1/image/crop?url=https://toolkitapi.io/static/samples/sample-image.png&mode=coordinates&x=100&y=50&width=800&height=600"
import httpx

resp = httpx.get(
    "https://image.toolkitapi.io/v1/image/crop?url=https://toolkitapi.io/static/samples/sample-image.png&mode=coordinates&x=100&y=50&width=800&height=600",
)
print(resp.json())
const resp = await fetch("https://image.toolkitapi.io/v1/image/crop?url=https://toolkitapi.io/static/samples/sample-image.png&mode=coordinates&x=100&y=50&width=800&height=600", {
});
const data = await resp.json();
console.log(data);
# See curl example
Response 200 OK
{
  "image": "/9j/4AAQSkZJRgABAQ...(base64 data)...",
  "format": "png",
  "original_size": {"width": 1920, "height": 1080},
  "crop_box": {"x": 100, "y": 50, "width": 800, "height": 600},
  "new_size": {"width": 800, "height": 600}
}

Try It Live

Live Demo

Description

Crop an image by coordinates, center-gravity, or smart square

How to Use

1

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

2

2. Choose a `mode`: `coordinates` (provide x, y, width, height), `smart` (center crop), or `square` (largest centered square).

3

3. For `coordinates` mode, specify `x`, `y`, `width`, and `height` in pixels.

4

4. The response includes the original size, crop box used, and the new dimensions.

About This Tool

Use the Image Crop endpoint to extract a rectangular region from any image. Three crop modes are available: `coordinates` for explicit pixel-based cropping, `smart` for center-gravity cropping to the smaller dimension, and `square` for extracting the largest centered square.

The smart and square modes are great for generating consistent thumbnails and profile pictures without manual coordinate calculation.

Why Use This Tool

Frequently Asked Questions

What is the difference between smart and square modes?
Both produce center-cropped results. `smart` crops to the smaller dimension (so a 1920×1080 image becomes 1080×1080), and `square` does the same — they produce identical results for non-square images.
What happens if crop coordinates exceed image bounds?
PIL will crop to the intersection of the crop box and the image. Areas outside the image boundary are excluded from the result.
Can I crop to a specific aspect ratio?
Use `coordinates` mode and calculate the box dimensions for your desired aspect ratio based on the image size returned by the metadata endpoint.

Start using Image Crop now

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