Crop image
Try it interactively →POST /api/image-cropCrop an image to a specified rectangle. Configurable x / y / width / height in pixels. Output keeps the input format by default.
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| image* | file | — | Input image (PNG / JPEG / WebP). |
| x* | number (0…16384) | — | Left edge of the crop rect, in source pixels. |
| y* | number (0…16384) | — | Top edge of the crop rect, in source pixels. |
| width* | number (1…16384) | — | Crop rect width. |
| height* | number (1…16384) | — | Crop rect height. |
| format | enum (png | jpeg | webp) | — | Output format. Defaults to the input's format. |
Response
Modes: binary, base64-json. Cache: yes (24h TTL).
Code samples
Built from the crop-quarter example.
# Download or substitute the example input:
# curl -O https://xtract.bot/examples/image-resize-jpeg/sample.jpg
IMAGE=$(base64 -w0 < sample.jpg)
curl -X POST https://api.xtract.bot/api/image-crop \
-H "Content-Type: application/json" \
-H "Accept: application/octet-stream" \
-H "X-Account-Id: $XTRACT_ACCOUNT_ID" \
-H "X-Api-Key: $XTRACT_API_KEY" \
-d '{
"x": 0,
"y": 0,
"width": 16,
"height": 16,
"image": "'"$IMAGE"'"
}'