矢量图快速接口

1. 接口地址

https://www.hidreamai.com/api-pub/gw/v2/image/img2svg/sync

 

2. 请求方式

POST

 

3. 请求参数

Header

参数 类型 是否必填 说明
Authorization string 客户授权Token
Content-Type string 使用json传参
X-accept-language string 语言偏好,支持['en', 'zh'],en:英文,zh:中文,默认"zh"
API-User-ID string 用户唯一标识

Body

参数 类型 是否必填 说明
image string 待转矢量图的图片,支持传入图片的base64值/URL地址
mode string 生成模式(支持'fast'和'slow'两种参数,前者速度快,后者精度高速度慢)

curl示例

curl -H 'Authorization: Bearer {USER_Authorization}' \
     -H 'Content-Type: application/json' \
     -X POST \
     -d '{
        "image": {image},
        "mode": "fast",
     }' \
     -v 'https://www.hidreamai.com/api-pub/gw/v2/image/img2svg/sync'

Python示例

import requests
import json
import uuid

USER_Authorization = <token>  # 获取方式详见接口文档https://www.hidreamai.com/docs/pixeling/user/token.html


# 请求头
headers = {
    'Authorization': f'Bearer {USER_Authorization}',
    'Content-Type': 'application/json',
    "X-accept-language": "en",
    'API-User-ID': ''  # 可选的用户唯一标识
}

# 请求体参数
data = {
    "image": <image>,  # 必要参数
    "mode": "fast"  # 必要参数
}

# 发送POST请求
url = 'https://www.hidreamai.com/api-pub/gw/v2/image/img2svg/sync'
response = requests.post(url, headers=headers, data=json.dumps(data))

# 处理响应
if response.status_code == 200:
    if response.json()['code'] == 0:
        svg = response.json()['result']['svg']
        print(svg)
    else:
        print(response.json()['message'])
else:
    print(response.status_code)

 

4. 返回参数

参数 类型 说明
code int 返回状态码
message string 返回状态信息
request_id string 本次请求的ID
result dict 返回结果

其中返回结果 result字段具体为:

参数 类型 说明
svg string 生成的快速矢量图的地址

示例

{
    "code": 0,
    "message": "Success",
    "request_id": "3ff6ecda-bf39-11ee-bd8f-165409f63db7",
    "result": {
        "svg": "https://media.hidreamai.com/4002b6a0-bf39-11ee-89f3-668a348da321_pre.svg"
    }
}

results matching ""

    No results matching ""

    results matching ""

      No results matching ""