Files
SnapOtter/apps/docs/zh-TW/tools/image/compress.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.1 KiB
Raw Blame History

description, i18n_source_hash, i18n_provenance, i18n_output_hash
description i18n_source_hash i18n_provenance i18n_output_hash
依品質層級或目標檔案大小縮減圖片檔案大小。 af4685da7e64 human 87b36988f2d2

壓縮

透過指定品質層級或以 KB 為單位的目標檔案大小來縮減圖片檔案大小。此工具使用迭代式二元搜尋以精準達到大小目標。

API 端點

POST /api/v1/tools/image/compress

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

參數

參數 類型 必填 預設值 說明
mode string "quality" 壓縮模式:qualitytargetSize
quality number 80 品質層級(1-100)。當模式為 quality 時使用。
targetSizeKb number - 以 KB 為單位的目標檔案大小。當模式為 targetSize 時使用。

範例請求

壓縮至品質 60

curl -X POST http://localhost:1349/api/v1/tools/image/compress \
  -H "Authorization: Bearer si_your-api-key" \
  -F "file=@photo.jpg" \
  -F 'settings={"mode": "quality", "quality": 60}'

壓縮至目標大小 200 KB

curl -X POST http://localhost:1349/api/v1/tools/image/compress \
  -H "Authorization: Bearer si_your-api-key" \
  -F "file=@photo.jpg" \
  -F 'settings={"mode": "targetSize", "targetSizeKb": 200}'

範例回應

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

備註

  • quality 模式下,數值越低,檔案越小,但壓縮失真也越多。值為 80 是網頁使用的良好預設。
  • targetSize 模式下,引擎會執行迭代壓縮,在不超過目標的前提下盡可能逼近目標。
  • 輸出格式與輸入格式相符。壓縮套用於該格式的原生編碼(例如 JPEG 檔案用 JPEG 品質,WebP 檔案用 WebP 品質)。
  • 若預設品質(80)可接受,可完全省略 quality 參數。