
Crop Image API
Crop a photo or image in your browser with a draggable box, exact pixel sizes and aspect ratios like 1:1, 16:9 and 4:5. Rotate, flip or cut a circle, then save at full quality.
All API requests require a valid API key passed in the Authorization header as a Bearer token.
20 requests per minute
1 endpoint available
Overview
Crop an image at full resolution. Give a box in pixels with x, y,
width and height, or leave them out and pick an aspect to get the largest
centred box of that shape. You can turn the image in quarter turns, flip it, and cut a circle with transparent
corners. Send the image as multipart form data in the file field. The response body is the cropped
image file.
Coordinates
The box is measured in pixels on the image as it looks after its EXIF orientation, then rotate
(clockwise), then the flips. With rotate=90, a 4000 x 3000 photo is 3000 wide and 4000 tall. The box
must fit inside the image, or the API returns 400 with the image size.
Notes
- Accepted input: JPEG, PNG, WebP, GIF, AVIF, TIFF and SVG, up to 20 MB and 50 megapixels. BMP, ICO and HEIC files return 415. Animated GIFs use the first frame.
- Send all four of
x,y,widthandheight, or none. When a box is sent,aspectis ignored. formatdefaults to the input's: JPEG stays JPEG, WebP stays WebP, anything else becomes PNG. A circle crop needs PNG or WebP, so a JPEG input defaults to PNG andformat=jpegwithcircle=truereturns 400.- JPG output fills any transparent pixels with white.
Endpoints
https://opentools.ca/api/v1/tools/crop-imageRequest Body
Content-Type: multipart/form-data
| Parameter | Type | Required | Description |
|---|---|---|---|
| file | file | Required | The image, up to 20 MB and 50 megapixels. JPEG, PNG, WebP, GIF (first frame), AVIF, TIFF or SVG. |
| x | number | Optional | Left edge of the box in pixels. |
| y | number | Optional | Top edge of the box in pixels. |
| width | number | Optional | Box width in pixels, at least 1. |
| height | number | Optional | Box height in pixels, at least 1. |
| aspect | string Enum: free, original, 1:1, 4:3, 3:2, 16:9, 9:16, 4:5 | Optional | Shape of the centred box when no box is sent. "free" keeps the whole image; "original" is the image's own ratio.Default: free |
| rotate | number Enum: 0, 90, 180, 270 | Optional | Clockwise quarter turns applied before cropping.Default: 0 |
| flipH | boolean | Optional | Mirror left to right (after rotating). "true" or "false".Default: false |
| flipV | boolean | Optional | Mirror top to bottom (after rotating). "true" or "false".Default: false |
| circle | boolean | Optional | Cut an ellipse that fills the box, with transparent corners. "true" or "false".Default: false |
| format | string Enum: png, jpeg, webp | Optional | Output format. Defaults to the input's format (see notes). |
| quality | number | Optional | Quality from 40 to 100, for jpeg and webp.Default: 92 |
Response Example
HTTP/1.1 200 OK
Content-Type: image/png
Content-Disposition: attachment; filename="avatar-cropped.png"
<binary file data>Error Codes
Code Examples
# Crop a 1200 x 800 box
curl -X POST https://opentools.ca/api/v1/tools/crop-image \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@photo.jpg" \
-F "x=400" -F "y=300" -F "width=1200" -F "height=800" \
-o photo-cropped.jpg
# Round avatar from the largest centred square
curl -X POST https://opentools.ca/api/v1/tools/crop-image \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@portrait.jpg" \
-F "aspect=1:1" \
-F "circle=true" \
-o avatar.pngRather use it in your browser? Open the Crop Image