Files
SnapOtter/apps/docs/zh-TW/tools/image/background-replace.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
使用 AI 將影像背景替換為純色或漸層。 930fe8890e55 human 51c11d8ea37f

Background Replace

將影像背景替換為純色或漸層。AI 模型會偵測主體、移除原始背景,並將主體合成到你所選的背景上。

API Endpoint

POST /api/v1/tools/image/background-replace

接受包含影像檔案及 JSON settings 欄位的 multipart form data。

Parameters

Parameter Type Required Default Description
backgroundType string No "color" 背景模式:colorgradient
color string No "#ffffff" 背景十六進位色碼(當 backgroundType 為 color 時)
gradientColor1 string No - 第一個漸層十六進位色碼
gradientColor2 string No - 第二個漸層十六進位色碼
gradientAngle integer No 180 漸層角度(0-360 度)
feather integer No 0 邊緣羽化半徑(0-20
format string No "png" 輸出格式:pngwebp

Example Request

curl -X POST http://localhost:1349/api/v1/tools/image/background-replace \
  -H "Authorization: Bearer si_your-api-key" \
  -F "file=@photo.jpg" \
  -F 'settings={"backgroundType": "color", "color": "#2563eb", "feather": 2}'

Example Response

{
  "jobId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "async": true
}

可透過 SSE 在 GET /api/v1/jobs/{jobId}/progress 追蹤進度。當工作完成時,SSE 串流會發出帶有下載 URL 的 completed 事件。

Notes

  • 這是一個 AI 驅動的工具,會回傳 202 Accepted 並以非同步方式處理。請連線至 SSE 端點以接收進度更新與最終結果。
  • 需要安裝 background-removal 功能套件。若套件不可用,會回傳 501
  • HEIC、RAW、PSD 及 SVG 輸入會在處理前自動解碼。
  • 輸出預設為 PNG,以保留主體周圍的透明度。