海报生成 API
请求地址
/services/screenshot
请求方法
POST
headers
请遵循鉴权 token 的相关配置
Content-Type: application/json
参数说明
JSON
参数 | 必需 | 说明 |
---|---|---|
device | 否 | string,设备名,详见 device 部分 |
custom_device | 否 | custom_device 对象 |
full_page | 否 | bool,是否滚动到页面最下方生成完整长图,默认为 true |
type | 否 | string,生成图片类型,可选值为 jpg png ,默认为 jpg |
quality | 否 | number,图片质量,仅当 取值范围是 10-100 整数,100 为最佳,默认值 90 |
template | 否 | string,需要渲染模板的 id |
data | 否 | object,当 template 有值时使用 表示渲染模板的参数,详见 模版渲染 |
url | 否 | string,需要渲染页面的 URL |
html | 否 | string,需要渲染的 HTML |
omit_background | 否 | bool,背景是否透明,默认为 当为 |
headers | 否 | object,URL 渲染时的自定义请求头,详见 URL 渲染 |
渲染方式
渲染方式有三种
template
url
html
,三选一即可。如果同时存在的参数超过一种,那么将按照
template > url > html
的优先级进行选择。
device
从我们支持的 设备列表 中选择的设备名称 name
custom_device
参数 | 必需 | 说明 |
---|---|---|
name | 否 | string,设备名 |
userAgent | 否 | string,user agent |
viewport.width | 否 | number,宽度像素 |
viewport.height | 否 | number,高度像素 |
viewport.deviceScaleFactor | 否 | number,屏幕缩放比例 |
viewport.isMobile | 否 | bool,是否为移动设备 |
viewport.hasTouch | 否 | bool,是否可触控 |
viewport.isLandscape | 否 | string,是否为 landscape(横屏)模式 |
你可以依据自己的需求,传递自己所需的设备类型,以满足高度定制化需求(例如:配置正方形屏幕以生成正方形分享图)
样例:
{
"name":"iPhone 5",
"userAgent":"Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1",
"viewport":{
"width":320,
"height":568,
"deviceScaleFactor":2,
"isMobile":true,
"hasTouch":true,
"isLandscape":false
}
}
设备选择
设备选择的方式有两种
custom_device
device
,二选一即可。如果同时存在的参数超过一种,那么将按照
custom_device > device
的优先级进行选择。
水印
免费账号均享有 100 张测试海报,测试海报生成带有快海报网址水印。
成为付费账号后,生成海报无水印,原剩余测试张数转为正式张数,并与新购张数累加。
无水印图


有水印图


请求样例
cURL
curl -X "POST" "https://api.kuaihaibao.com/services/screenshot" \
-H 'Authorization: Bearer YOUR_TOKEN_HERE' \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"template": "h9zuu2zh",
"data": {
"qrcode": "https://khb-sample.oss-cn-shanghai.aliyuncs.com/sample/sample_qr_0.png",
"records": [
{
"label": "累积打卡",
"number": "50",
"unit": "天"
},
{
"label": "学习时间",
"number": "60",
"unit": "分钟"
},
{
"label": "行动力超过",
"number": "70",
"unit": "% 的同学"
}
],
"tip": "刚刚完成了打卡",
"slogan": "小程序分享海报生成服务",
"companyColor": "#fff",
"company": "快海报",
"brand": "快海报",
"backgroundImage": "https://khb-sample.oss-cn-shanghai.aliyuncs.com/sample/laptop.jpg",
"backgroundColor": "#111",
"user": {
"avatar": "https://khb-sample.oss-cn-shanghai.aliyuncs.com/sample/girl_2.jpg",
"nickname": "筱墨"
}
}
}'
JavaScript (axios 版本)
axios({
"method": "POST",
"url": "https://api.kuaihaibao.com/services/screenshot",
"headers": {
"Authorization": "Bearer YOUR_TOKEN_HERE",
"Content-Type": "application/json; charset=utf-8"
},
"data": {
"template": "h9zuu2zh",
"data": {
"qrcode": "https://khb-sample.oss-cn-shanghai.aliyuncs.com/sample/sample_qr_0.png",
"records": [
{
"label": "累积打卡",
"number": "50",
"unit": "天"
},
{
"label": "学习时间",
"number": "60",
"unit": "分钟"
},
{
"label": "行动力超过",
"number": "70",
"unit": "% 的同学"
}
],
"tip": "刚刚完成了打卡",
"slogan": "小程序分享海报生成服务",
"companyColor": "#fff",
"company": "快海报",
"brand": "快海报",
"backgroundImage": "https://khb-sample.oss-cn-shanghai.aliyuncs.com/sample/laptop.jpg",
"backgroundColor": "#111",
"user": {
"avatar": "https://khb-sample.oss-cn-shanghai.aliyuncs.com/sample/girl_2.jpg",
"nickname": "筱墨"
}
}
}
})
Python
import requests
response = requests.post(
url="https://api.kuaihaibao.com/services/screenshot",
headers={
"Authorization": "Bearer YOUR_TOKEN_HERE",
},
json={
"template": "h9zuu2zh",
"data": {
"qrcode": "https://khb-sample.oss-cn-shanghai.aliyuncs.com/sample/sample_qr_0.png",
"records": [
{
"label": "累积打卡",
"number": "50",
"unit": "天"
},
{
"label": "学习时间",
"number": "60",
"unit": "分钟"
},
{
"label": "行动力超过",
"number": "70",
"unit": "% 的同学"
}
],
"tip": "刚刚完成了打卡",
"slogan": "小程序分享海报生成服务",
"companyColor": "#fff",
"company": "快海报",
"brand": "快海报",
"backgroundImage": "https://khb-sample.oss-cn-shanghai.aliyuncs.com/sample/laptop.jpg",
"backgroundColor": "#111",
"user": {
"avatar": "https://khb-sample.oss-cn-shanghai.aliyuncs.com/sample/girl_2.jpg",
"nickname": "筱墨"
}
}
}
)