This page was machine-translated. Spotted a mistake?Help improve it.
Skip to content

裁切

透過位置與大小定義矩形區域來裁切圖片。支援像素與百分比兩種單位。

API 端點

POST /api/v1/tools/image/crop

接受包含圖片檔案與 JSON settings 欄位的 multipart 表單資料。

參數

參數類型必填預設值說明
leftnumber-裁切區域的 X 偏移(自左邊緣起算)
topnumber-裁切區域的 Y 偏移(自上邊緣起算)
widthnumber-裁切區域的寬度
heightnumber-裁切區域的高度
unitstring"px"數值的單位:pxpercent

範例請求

bash
curl -X POST http://localhost:1349/api/v1/tools/image/crop \
  -H "Authorization: Bearer si_your-api-key" \
  -F "[email protected]" \
  -F 'settings={"left": 100, "top": 50, "width": 800, "height": 600}'

使用百分比值裁切:

bash
curl -X POST http://localhost:1349/api/v1/tools/image/crop \
  -H "Authorization: Bearer si_your-api-key" \
  -F "[email protected]" \
  -F 'settings={"left": 10, "top": 10, "width": 80, "height": 80, "unit": "percent"}'

範例回應

json
{
  "jobId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "downloadUrl": "/api/v1/download/a1b2c3d4-e5f6-7890-abcd-ef1234567890/photo.jpg",
  "originalSize": 2450000,
  "processedSize": 1200000
}

備註

  • 裁切區域必須落在圖片邊界之內。若區域超出圖片,請求將會失敗。
  • 使用 percent 單位時,數值代表圖片尺寸的百分比(例如 left: 10 表示距左邊緣 10%)。
  • 輸出格式與輸入格式相符。
  • 裁切前會自動套用 EXIF 方向,因此座標對應到視覺上正確的方向。