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

description, i18n_source_hash, i18n_provenance, i18n_output_hash
description i18n_source_hash i18n_provenance i18n_output_hash
使用 AI 抠图(BiRefNet)修复伪透明 PNG,生成真正的 alpha 通道,并进行去边缘杂色清理。 7eb748b80f93 human bf179732f8ea

PNG 透明度修复器

一键修复伪透明 PNG。使用 AI 抠图(BiRefNet HR Matting 模型)生成真正的 alpha 透明度,并通过去边缘后处理清理边缘。

API 端点

POST /api/v1/tools/image/transparency-fixer

处理方式: 异步(返回 202,通过 SSE 轮询 /api/v1/jobs/{jobId}/progress 获取状态)

模型包: background-removal4-5 GB

参数

参数 类型 必填 默认值 说明
file file - 图像文件(multipart
defringe number 30 去边缘强度(0-100)。移除边缘周围的半透明杂色像素
outputFormat string "png" 输出格式:pngwebp
removeWatermark boolean false 应用水印移除预处理(中值滤波)

示例请求

curl -X POST http://localhost:1349/api/v1/tools/image/transparency-fixer \
  -F "file=@fake-transparent.png" \
  -F 'settings={"defringe":40,"outputFormat":"png"}'

响应

初始响应(202 Accepted

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

进度(SSE,位于 /api/v1/jobs/{jobId}/progress

event: progress
data: {"phase":"processing","stage":"Processing transparency...","percent":50}

最终结果(通过 SSE

{
  "phase": "complete",
  "percent": 100,
  "result": {
    "jobId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "downloadUrl": "/api/v1/download/{jobId}/fake-transparent_fixed.png",
    "originalSize": 180000,
    "processedSize": 150000,
    "filename": "fake-transparent.png"
  }
}

说明

  • 需要安装 background-removal 模型包(4-5 GB)。
  • 使用 birefnet-hr-matting 作为高质量 alpha 抠图的主模型。如果 HR 模型内存不足,则回退到 birefnet-general
  • defringe 选项移除 AI 抠图有时在头发、毛发和细边缘周围留下的半透明杂色像素。其原理是模糊 alpha 通道并将低置信度像素置零。
  • removeWatermark 选项应用中值滤波预处理步骤。这是一种基础的水印削弱,而非专用的水印移除工具。
  • 仅输出 PNG 或无损 WebP(两者都支持 alpha 透明度)。
  • 通过自动解码支持 HEIC/HEIF、RAW、TGA、PSD、EXR 和 HDR 输入格式。