Skip to content

图片转 SVG(To SVG)

将位图(JPEG / PNG 等)转换为可缩放矢量图形(SVG),支持彩色与黑白两种转换模式,适用于 Logo 提取、图标制作、激光雕刻等场景。

基本信息

项目
接口路径POST /image/to-svg
所需 Scopeto_svg(规范名)或别名 2svg,或 *

| 任务类型 | 异步,返回 taskId |


请求参数

json
{
  "requestId": "可选,调用方自定义唯一 ID",
  "url": "原图的公开 HTTPS URL(必填)",
  "conversionMode": "color",
  "numColors": 16,
  "threshold": 128,
  "detailLevel": "medium",
  "backgroundRect": true
}

参数说明

参数类型必填默认值说明
requestIdstringnull调用方请求 ID,用于幂等去重
urlstring原图的公开 HTTPS URL
conversionModestringcolor转换模式:color(彩色)或 blackwhite(黑白)
numColorsinteger16彩色模式下保留的颜色数量
thresholdinteger128黑白模式下的二值化阈值(0 ~ 255)
detailLevelstringmedium矢量化细节程度:lowmediumhigh
backgroundRectbooleantrue是否在 SVG 中生成背景矩形

请求示例

彩色转换(默认):

bash
curl -s -X POST \
  -H "Authorization: Bearer $TUSEN_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/logo.png",
    "numColors": 8,
    "detailLevel": "high"
  }' \
  "https://magiqsight.com/openapi/v1/image/to-svg"

黑白矢量化(适合线稿/图标):

bash
curl -s -X POST \
  -H "Authorization: Bearer $TUSEN_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/sketch.png",
    "conversionMode": "blackwhite",
    "threshold": 180,
    "backgroundRect": false
  }' \
  "https://magiqsight.com/openapi/v1/image/to-svg"

响应示例

json
{
  "code": 0,
  "data": {
    "requestId": "req_abc123",
    "taskId": "task_xyz"
  },
  "msg": ""
}

获得 taskId 后,通过 GET /tasks/{taskId} 轮询结果。

任务成功(status: 1)后,resultTypetext,SVG 内容以 XML 字符串形式存放在 textResult 字段中,imageUrls 不含结果。

json
{
  "taskType": "2svg",
  "status": 1,
  "resultType": "text",
  "textResult": "<svg xmlns=\"http://www.w3.org/2000/svg\" ...",
  "imageUrls": []
}

妙图设计 API Beta