Crop Image

Crop Image API

Design

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.

Authentication

All API requests require a valid API key passed in the Authorization header as a Bearer token.

Rate Limit

20 requests per minute

Endpoints

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, width and height, or none. When a box is sent, aspect is ignored.
  • format defaults 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 and format=jpeg with circle=true returns 400.
  • JPG output fills any transparent pixels with white.

Endpoints

POST
https://opentools.ca/api/v1/tools/crop-image
Crop an image to a box or an aspect ratio

Request Body

Content-Type: multipart/form-data

ParameterTypeRequiredDescription
file
file
Required
The image, up to 20 MB and 50 megapixels. JPEG, PNG, WebP, GIF (first frame), AVIF, TIFF or SVG.
x
number
OptionalLeft edge of the box in pixels.
y
number
OptionalTop edge of the box in pixels.
width
number
OptionalBox width in pixels, at least 1.
height
number
OptionalBox height in pixels, at least 1.
aspect
string
Enum: free, original, 1:1, 4:3, 3:2, 16:9, 9:16, 4:5
OptionalShape 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
OptionalClockwise quarter turns applied before cropping.Default: 0
flipH
boolean
OptionalMirror left to right (after rotating). "true" or "false".Default: false
flipV
boolean
OptionalMirror top to bottom (after rotating). "true" or "false".Default: false
circle
boolean
OptionalCut an ellipse that fills the box, with transparent corners. "true" or "false".Default: false
format
string
Enum: png, jpeg, webp
OptionalOutput format. Defaults to the input's format (see notes).
quality
number
OptionalQuality 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

400
Bad Request - Missing file, invalid option, partial box, box outside the image, or a circle saved as JPEG
401
Unauthorized - Invalid or missing API key
403
Forbidden - API key is inactive or expired, or the request IP is not allowed
413
Payload Too Large - File over 20 MB or image over 50 megapixels
415
Unsupported Media Type - Not an image the server can read (BMP, ICO and HEIC are not supported)
429
Too Many Requests - Rate limit exceeded
500
Internal Server Error

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.png

Ready to get started?

Create an API key to start using the Crop Image API.

Rather use it in your browser? Open the Crop Image