xtract.bot
POST /api/image-grayscale

Convert an image to greyscale. Multiple luminance methods: Rec.709 (perceptual, default), Rec.601, Average, Lightness, RMS.

Converts an image to greyscale. Available luminance methods: - `Rec.709` (default): the modern perceptual standard. Use this for photos. - `Rec.601`: the older perceptual standard. Slightly different greyscale tones, occasionally needed for legacy compatibility. - `Average`: plain `(R+G+B)/3`. Quick but visually flat. - `Lightness`: `(max+min)/2`, the HSL "lightness". - `RMS`: root-mean-square. Output format defaults to the input format. Override with `format` to convert in the same call.

Inputs

NameTypeDefaultDescription
image*fileInput image (PNG / JPEG / WebP).
methodenum (Rec709Luma | Rec601Luma | Average | Brightness | Lightness | RMS | Undefined)"Rec709Luma"Pixel-intensity formula.
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 default-png example.

# Download or substitute the example input:
#   curl -O https://xtract.bot/examples/image-png-to-webp/sample.png
IMAGE=$(base64 -w0 < sample.png)

curl -X POST https://api.xtract.bot/api/image-grayscale \
  -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 '{
  "method": "Rec709Luma",
  "image": "'"$IMAGE"'"
}'