Files
SnapOtter/apps/docs/zh-TW/tools/image/gif-tools.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

5.2 KiB
Raw Blame History

description, i18n_source_hash, i18n_provenance, i18n_output_hash
description i18n_source_hash i18n_provenance i18n_output_hash
在單一工具中對動態 GIF 進行縮放、最佳化、變速、反轉、旋轉並擷取影格。 5e525e80db92 human f09b6c1fd108

GIF 工具

縮放、最佳化、變速、反轉、擷取影格並旋轉動態 GIF。在單一工具中提供多種操作模式。

API 端點

POST /api/v1/tools/image/gif-tools

參數

共用參數

參數 型別 必填 預設值 說明
mode string "resize" 操作模式:resizeoptimizespeedreverseextractrotate
loop number 0 輸出 GIF 的循環次數(0 = 無限,1-100 = 有限循環)

縮放模式參數

參數 型別 必填 預設值 說明
width integer - 目標寬度(像素,1 到 16384
height integer - 目標高度(像素,1 到 16384
percentage number - 依百分比縮放(1 到 500)。設定後會覆寫 width/height。

最佳化模式參數

參數 型別 必填 預設值 說明
colors number 256 調色盤中的最大顏色數(2 到 256
dither number 1.0 抖動強度(0 到 1,0 表示停用抖動)
effort number 7 最佳化強度等級(1 到 10,越高越慢但檔案越小)

變速模式參數

參數 型別 必填 預設值 說明
speedFactor number 1.0 速度倍率(0.1 到 10)。大於 1 加速,小於 1 減速。

擷取模式參數

參數 型別 必填 預設值 說明
extractMode string "single" 擷取模式:singlerangeall
frameNumber number 0 single 模式下要擷取的影格索引(從 0 起算)
frameStart number 0 range 模式的起始影格索引(從 0 起算)
frameEnd number - range 模式的結束影格索引(從 0 起算,含此值)
extractFormat string "png" 擷取影格的格式:pngwebp

旋轉模式參數

參數 型別 必填 預設值 說明
angle number - 旋轉角度:90180270
flipH boolean false 水平翻轉
flipV boolean false 垂直翻轉

範例請求

縮放

curl -X POST http://localhost:1349/api/v1/tools/image/gif-tools \
  -F "file=@animation.gif" \
  -F 'settings={"mode":"resize","percentage":50}'

最佳化

curl -X POST http://localhost:1349/api/v1/tools/image/gif-tools \
  -F "file=@large.gif" \
  -F 'settings={"mode":"optimize","colors":128,"effort":9}'

加速

curl -X POST http://localhost:1349/api/v1/tools/image/gif-tools \
  -F "file=@animation.gif" \
  -F 'settings={"mode":"speed","speedFactor":2.0}'

擷取單一影格

curl -X POST http://localhost:1349/api/v1/tools/image/gif-tools \
  -F "file=@animation.gif" \
  -F 'settings={"mode":"extract","extractMode":"single","frameNumber":5,"extractFormat":"png"}'

範例回應

{
  "jobId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "downloadUrl": "/api/v1/download/a1b2c3d4-e5f6-7890-abcd-ef1234567890/animation.gif",
  "originalSize": 2345678,
  "processedSize": 1234567
}

Info 子路由

POST /api/v1/tools/image/gif-tools/info

傳回動態 GIF 的中繼資料,而不對其進行處理。

Info 請求

curl -X POST http://localhost:1349/api/v1/tools/image/gif-tools/info \
  -F "file=@animation.gif"

Info 回應

{
  "width": 480,
  "height": 320,
  "pages": 24,
  "delay": [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],
  "loop": 0,
  "fileSize": 2345678,
  "duration": 2400
}

注意事項

  • 主處理端點使用標準的 createToolRoute factory。
  • info 端點僅需上傳檔案(不需要設定)。
  • resize 模式下,若提供了 percentage,它會優先於 width/height。縮放時使用 fit: inside 以維持長寬比。
  • speed 模式下,影格延遲會除以速度係數。每影格最小延遲為 20ms(GIF 規格限制)。
  • reverse 模式下,也可使用 speedFactor 參數,在反轉的同時調整速度。
  • extract 模式下搭配 rangeall 時,輸出為包含個別影格的 ZIP 檔案。
  • rotate 模式下,每個影格會被個別處理並重新組合為動畫。
  • loop 參數控制輸出 GIF 循環的次數。使用 0 表示無限循環。
  • info 回應中的 duration 欄位是動畫的總時長(毫秒)。