提交智能拓图任务
1. 接口地址
https://www.hidreamai.com/api-pub/gw/v2/image/outpainting/async
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地址 |
height | int | 是 | 图片的高(上限1024),默认值为1024 |
width | int | 是 | 图片的宽(上限1024),默认值为1024 |
x_offset | int | 是 | 图片的x轴坐标,默认值为0 |
y_offset | int | 是 | 图片的y轴坐标,默认值为0 |
notify_url | string | 否 | 任务完成回调通知接口(需公网能访问),请求体包含main_task_id(任务的task_id)、sub_task_results |
说明:
1.image:需要预先将图片resize至原图在拓展图中的相对尺寸,如:扩展图的尺寸是10241024,原图占扩展图的1/4,那么传入的原图就要resize成512\512
2.x_offset、y_offset:需要根据原图在扩展图中的位置进行计算,如:扩展图的尺寸是1024*1024,原图占扩展图的1/4,且居中,则x_offset=(1024-512)/2,y_offset=(1024-512)/2
curl示例
curl -H 'Authorization: Bearer {USER_Authorization}' \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"image": {image},
"height": 1024,
"width": 1024,
"x_offset": 10,
"y_offset": 10,
}' \
-v 'https://www.hidreamai.com/api-pub/gw/v2/image/outpainting/async'
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',
'API-User-ID': '' # 可选的用户唯一标识
}
# 请求体参数
data = {
"image": "https://storage.hidreamai.com/image/p_62ded166-d6b0-11ee-a835-00163e038297.png", # 必要参数
"width": 1024, # 必要参数
"height": 1024, # 必要参数
"x_offset": 100, # 必要参数
"y_offset": 100 # 必要参数
}
# 发送POST请求
url = 'https://www.hidreamai.com/api-pub/gw/v2/image/outpainting/async'
response = requests.post(url, headers=headers, data=json.dumps(data))
# 处理响应
if response.status_code == 200:
if response.json()['code'] == 0:
task_id = response.json()['result']['task_id']
print(task_id)
else:
print(response.json()['message'])
else:
print(response.status_code)
4. 返回参数
参数 | 类型 | 说明 |
---|---|---|
code | int | 返回状态码 |
message | string | 返回状态信息 |
request_id | string | 本次请求的ID |
result | dict | 返回结果 |
其中返回结果 result字段具体为:
参数 | 类型 | 说明 |
---|---|---|
task_id | string | 返回任务ID |
sub_task_ids | list | 返回子任务ID的列表,子任务定义为生成单张图片的任务 |
示例:
{
"code":0,
"message":"Success",
"request_id":"ccfc092e-8430-11ee-97ff-f60f825045d5",
"result":{
"sub_task_ids":["7ae9bc98-db8f-4bf7-86ff-e5bdd84e2311"],
"task_id":"cd23b1ae-8430-11ee-97ff-f60f825045d5"
}
}