Skip to content

任务:证件照

简洁描述:使用证件照接口生成标准尺寸的证件照图像。


概览

  • 请求方法:POST
  • 路径:/task/pic/idphoto
  • 内容类型:multipart/form-data

认证方式

  • Header:Authorization: Bearer <token>

请求示例

表单参数

参数类型必填说明
image_filefile源图像文件(二进制),与 image_url 二选一
image_urlstring源图像 URL,与 image_file 二选一
sizestring证件照尺寸,格式为 {width}x{height},例如 300x400,像素范围 100~2000
formatstring输出格式:png=透明背景,jpg=白色背景,默认 png
syncinteger是否等待结果就绪:0=异步(默认),1=同步
bg_colorstringJPG 背景色,格式为 RRGGBB,例如 FFFFFF,仅在 format=jpg 时生效
callback_urlstring回调通知地址

curl 示例

bash
curl -X POST "https://api.gpt.ge/task/pic/idphoto" \
  -H "Authorization: Bearer sk-xxxx" \
  -F "image_url=https://example.com/portrait.png" \
  -F "size=300x400" \
  -F "format=jpg" \
  -F "bg_color=FFFFFF" \
  -F "sync=1"

JavaScript (fetch) 示例

javascript
const formData = new FormData();
formData.append('image_url', 'https://example.com/portrait.png');
formData.append('size', '300x400');
formData.append('format', 'jpg');
formData.append('bg_color', 'FFFFFF');
formData.append('sync', '1');

fetch('https://api.gpt.ge/task/pic/idphoto', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer sk-xxxx'
  },
  body: formData
}).then(r => r.json()).then(console.log);

Python(requests)示例

python
import requests

url = 'https://api.gpt.ge/task/pic/idphoto'
headers = {
    'Authorization': 'Bearer sk-xxxx'
}

files = {
    'image_url': (None, 'https://example.com/portrait.png')
}
data = {
    'size': '300x400',
    'format': 'jpg',
    'bg_color': 'FFFFFF',
    'sync': '1'
}

response = requests.post(url, headers=headers, files=files, data=data)
print(response.json())

返回示例(200)

json
{
  "status": 200,
  "data": {
    "completed_at": 1742670627,
    "created_at": 1742670626,
    "download_time": 488,
    "err_info": "",
    "foreground_rect": {
      "x": 133,
      "y": 110,
      "width": 604,
      "height": 952
    },
    "image": "https://wxtechsz.oss-cn-shenzhen.aliyuncs.com/tasks/output/idphoto/3b950563-e53f-4036-a581-5ac04d0829b3-image.png",
    "image_height": 400,
    "image_width": 300,
    "output_type": 2,
    "processed_at": 1742670626,
    "progress": 100,
    "result_type": "object",
    "return_type": 1,
    "state": 1,
    "state_detail": "Complete",
    "task_id": "3b950563-e53f-4036-a581-5ac04d0829b3",
    "time_elapsed": 384.54998779296875,
    "type": "auto"
  }
}

注意:该接口使用 multipart/form-data 上传图像,建议仅使用 image_urlimage_file 中的一种方式提交源图像;bg_color 参数仅在 format=jpg 时生效。