xtract.bot
POST /api/image-crop

Crop an image to a specified rectangle. Configurable x / y / width / height in pixels. Output keeps the input format by default.

Returns the rectangular region defined by `x`, `y`, `width`, `height` (all in pixels, with the origin at the top-left). Output keeps the input format unless you pass `format` to re-encode in the same call.

Inputs

NameTypeDefaultDescription
image*fileInput 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.
formatenum (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"'"
}'