Files
SnapOtter/apps/docs/zh-TW/tools/image/crop.md
T
SnapOtterandGitHub 4963ab3bbd feat(docs-i18n): translate all documentation into 20 languages
All 181 docs markdown files translated into 20 languages (apps/docs/<locale>/**). Companion to the i18n code PR; admin-merged because the file count exceeds GitHub's per-PR CI trigger limit. Validated by pnpm i18n:check (all surfaces, 0 stale/missing) and a clean all-locale docs build.
2026-07-11 13:52:47 +08:00

2.0 KiB

description, i18n_source_hash, i18n_provenance, i18n_output_hash
description i18n_source_hash i18n_provenance i18n_output_hash
透過指定位置與尺寸的區域來裁切圖片。 aab38ccd7c53 human 702781822ff4

裁切

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

API 端點

POST /api/v1/tools/image/crop

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

參數

參數 類型 必填 預設值 說明
left number - 裁切區域的 X 偏移(自左邊緣起算)
top number - 裁切區域的 Y 偏移(自上邊緣起算)
width number - 裁切區域的寬度
height number - 裁切區域的高度
unit string "px" 數值的單位:pxpercent

範例請求

curl -X POST http://localhost:1349/api/v1/tools/image/crop \
  -H "Authorization: Bearer si_your-api-key" \
  -F "file=@photo.jpg" \
  -F 'settings={"left": 100, "top": 50, "width": 800, "height": 600}'

使用百分比值裁切:

curl -X POST http://localhost:1349/api/v1/tools/image/crop \
  -H "Authorization: Bearer si_your-api-key" \
  -F "file=@photo.jpg" \
  -F 'settings={"left": 10, "top": 10, "width": 80, "height": 80, "unit": "percent"}'

範例回應

{
  "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 方向,因此座標對應到視覺上正確的方向。