请求URL:https://api.shiliuai.com/api/id_photo/v1/couple
请求方式:POST
请求参数-请求头(Header):
参数 | 类型 | 说明 |
---|---|---|
Content-Type | string | application/json |
APIKEY | string | 您的API KEY |
请求参数-请求内容(Body):
分类 | 参数 | 是否必填 | 类型 | 说明 |
---|---|---|---|---|
图片 | ||||
base64 | 必须填写其中之一 | string | base64编码的图片文件(小于20M),需要传入base64或者id | |
id | string | 图片id,对于已经请求过的图片,如果需要改变水印,尺寸,颜色等参数,使用id而无需再上传base64 | ||
尺寸 | ||||
dpi | 否 | int | 生成证件照的dpi,默认为300,最大值1000 | |
pxWidth | 否 | int | 生成证件照的宽度(像素),可传入 (pxWidth, pxHeight) 或者 (mmWidth, mmHeight) 中的一对值,默认为 (295, 413),小于1800像素 | |
pxHeight | 否 | int | 生成证件照的高度(像素),小于1800像素 | |
mmWidth | 否 | int | 生成证件照的宽度(毫米),小于180毫米 | |
mmHeight | 否 | int | 生成证件照的高度(毫米),小于180毫米 | |
背景色 | ||||
changeBg | 否 | int | 0或1,是否抠图换背景,默认为1 | |
bgColor | 否 | string | 背景色的16进制表示,常用颜色有:白色:"FFFFFF",红色:"FF0000",蓝色:"438EDB",默认为白色 | |
美颜 | ||||
autoBright | 否 | int | 0或1,是否自动调光,默认为0 | |
brightFactor | 否 | float | [0, 1],调光系数,默认为0.5 | |
autoSmooth | 否 | int | 0或1,是否自动磨皮,默认为0 | |
smoothFactor | 否 | float | [0, 1],磨皮系数,默认为0.5 | |
autoThinFace | 否 | int | 0或1,是否自动瘦脸,默认为0 | |
thinFaceFactor | 否 | float | [0, 1],瘦脸系数,默认为0.5 | |
autoSharp | 否 | int | 0或1,是否自动锐化,默认为0 | |
sharpFactor | 否 | float | [0, 1],锐化系数,默认为0.5 | |
预览 | ||||
preview | 否 | int | 0或1,是否预览,预览有水印,不扣积分,默认为0 | |
watermarkID | 否 | string | 定制化水印id,默认用系统水印 | |
文件大小 | ||||
quality | 否 | int | 生成证件照的质量,[1, 100],越大生成的证件照文件越大,默认为92 | |
minFileSize | 否 | int | 生成证件照的最小文件大小,[0, inf],比如10240表示最小文件大小为10KB,只有当quality为空时起作用,默认为空 | |
maxFileSize | 否 | int | 生成证件照的最大文件大小,[0, inf],只有当quality为空时起作用,默认为空 | |
排版 | ||||
layout | 否 | int | 0或1,是否返回排版,默认为0 | |
layoutVertical | 否 | int | 0或1,返回横版或竖版排版,默认为横版 | |
layoutSize | 否 | string | "5inch"或"6inch",排版尺寸五寸或六寸,默认为"5inch" |
参数 | 说明 |
---|---|
code | 错误码 |
msg | 错误信息(英文) |
msg_cn | 错误信息(中文) |
id | 图片id,(当code==0时会有该返回值) |
result_base64 | 结婚照的base64编码,(当code==0时会有该返回值) |
layout_base64 | 排版的base64编码,(当code==0且请求参数layout==1时会有该返回值) |
错误码说明:
错误码 | 说明 |
---|---|
0 | 成功 |
1 | 图片错误 |
2 | 抠图错误 |
3 | 服务器繁忙 |
4 | 参数错误,具体错误看msg或msg_cn |
6 | 未知错误 |
7 | 图片id无效,可能已过期 |
8 | 图片人脸数不是2 |
101 | API-KEY不正确 |
102 | 未知用户 |
103 | 积分已用完 |
104 | 扣除积分失败 |
Python 代码示例:
import requests import base64 import cv2 import json import numpy as np api_key = '******' # 你的API KEY file_path = '...' # 图片路径 with open(file_path, 'rb') as fp: photo_base64 = base64.b64encode(fp.read()).decode('utf8') url = 'https://www.shiliuai.com/api/id_photo/v1/couple' headers = {'APIKEY': api_key, "Content-Type": "application/json"} data = { "base64": photo_base64, } response = requests.post(url=url, headers=headers, json=data) response = json.loads(response.content) """ 成功:{'code': 0, 'msg': 'OK', 'msg_cn': '成功', 'id': image id, ''result_base64': result_base64} or 失败:{'code': error_code, 'msg': error_msg, 'msg_cn': 错误信息} """ result_base64 = response['result_base64'] file_bytes = base64.b64decode(result_base64) f = open('result.jpg', 'wb') f.write(file_bytes) f.close() image = np.asarray(bytearray(file_bytes), dtype=np.uint8) image = cv2.imdecode(image, cv2.IMREAD_UNCHANGED) cv2.imshow('result', image) cv2.waitKey(0)
PHP 代码示例:
$url = "https://www.shiliuai.com/api/id_photo/v1/couple"; $method = "POST"; $apikey = "******"; $header = array(); array_push($header, "APIKEY:" . $apikey); array_push($header, "Content-Type:application/json"); $file_path = "..."; $handle = fopen($file_path, "r"); $photo = fread($handle, filesize($file_path)); fclose($handle); $photo_base64 = base64_encode($photo); $data = array( "base64"=> $photo_base64, ); $post_data = json_encode($data); $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); $response = curl_exec($curl); var_dump($response);