Files
SnapOtter/apps/docs/zh-CN/tools/image/text-overlay.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.4 KiB
Raw Blame History

description, i18n_source_hash, i18n_provenance, i18n_output_hash
description i18n_source_hash i18n_provenance i18n_output_hash
添加带投影和背景框的样式化文字叠加。 9f8e697188fc human d0640359fbc4

文字叠加

为图像添加带可选投影和半透明背景框的样式化文字。适用于照片上的标题、说明文字或注释。

API 端点

POST /api/v1/tools/image/text-overlay

接受包含图像文件和 JSON settings 字段的 multipart 表单数据。

参数

参数 类型 必填 默认值 说明
text string - 要叠加的文字(1 到 500 个字符)
fontSize number 48 字体大小(像素,8 到 200
color string "#FFFFFF" 文字颜色,十六进制格式(#RRGGBB
position string "bottom" 垂直位置:topcenterbottom
backgroundBox boolean false 在文字后显示半透明背景矩形
backgroundColor string "#000000" 背景框颜色,十六进制格式(#RRGGBB
shadow boolean true 在文字后应用投影

示例请求

curl -X POST http://localhost:1349/api/v1/tools/image/text-overlay \
  -H "Authorization: Bearer si_your-api-key" \
  -F "file=@photo.jpg" \
  -F 'settings={"text": "Hello World", "fontSize": 64, "color": "#FFFFFF", "position": "bottom", "shadow": true}'

带背景框:

curl -X POST http://localhost:1349/api/v1/tools/image/text-overlay \
  -H "Authorization: Bearer si_your-api-key" \
  -F "file=@photo.jpg" \
  -F 'settings={"text": "Caption", "fontSize": 36, "position": "bottom", "backgroundBox": true, "backgroundColor": "#000000"}'

示例响应

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

说明

  • 文字在图像中始终水平居中。
  • 投影使用 2px 偏移、3px 模糊,黑色不透明度为 70%。
  • 背景框跨越整个图像宽度,不透明度为 70%,高度与字体大小成比例(1.8 倍)。
  • 文字通过 SVG 合成渲染,因此使用系统默认的无衬线字体。
  • 文字中的 XML 特殊字符会被安全转义。
  • 输出格式与输入格式一致。HEIC、RAW、PSD 和 SVG 输入在处理前会自动解码。