Files
SnapOtter/apps/docs/zh-TW/tools/image/crop.md
T
SnapOtterandGitHub f858c4cea0 feat: clearer, disambiguated tool names across all surfaces (#520)
Renames 18 ambiguous or hard-to-search tool names so image tools self-qualify like the other modalities ("Compress" becomes "Compress Image"), and cleans up a few awkward names. Propagated across search (constants.ts), display (en.ts + 20 locales), the OpenAPI base spec + 20 locale specs, and the docs tool-page headings in 21 languages. Removes the duplicate "Normalize Audio" summary shared by the video and audio endpoints. Tool ids and routes are unchanged, so no API paths or bookmarks break.
2026-07-15 21:55:51 +08:00

2.0 KiB

description, i18n_source_hash, i18n_provenance, i18n_output_hash
description i18n_source_hash i18n_provenance i18n_output_hash
透過指定位置與尺寸的區域來裁切圖片。 556f37893553 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 方向,因此座標對應到視覺上正確的方向。