Files
SnapOtter/apps/docs/zh-CN/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.3 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 79a1cadb7164

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 工厂。
  • info 端点只需上传文件(无需设置)。
  • resize 模式下,如果提供了 percentage,它会优先于 width/height。调整大小使用 fit: inside 以保持宽高比。
  • speed 模式下,帧延迟会除以速度因子。每帧的最小延迟为 20ms(GIF 规范限制)。
  • reverse 模式下,还可使用 speedFactor 参数在反转的同时调整速度。
  • extract 模式且使用 rangeall 时,输出是包含各个帧的 ZIP 文件。
  • rotate 模式下,会单独处理每一帧并重新组装成动画。
  • loop 参数控制输出 GIF 的循环次数。使用 0 表示无限循环。
  • info 响应中的 duration 字段是以毫秒为单位的动画总时长。