imgrender 开放 API
  1. 图片生成
imgrender 开放 API
  • 接入必读
  • 状态码与错误码
  • 图片生成
    • 同步生成图片-v1
      POST
  1. 图片生成

同步生成图片-v1

POST
/v1/pics
根据传入的完整配置生成图片,返回图片的访问链接。
更多信息请查看 文档-生成图片

错误码#

错误码HTTP 状态码说明排查建议
20105403图片生成失败请根据提示信息处理

请求参数

Header 参数
X-API-Key
string 
必需
用于授权,详情见 https://www.imgrender.net/docs/dev/api/basic
示例值:
请替换为你的应用密钥
Body 参数application/json
width
integer 
宽度
必需
<= 1100> 0
height
integer 
高度
必需
<= 2480> 0
backgroundColor
string 
背景颜色
必需
必须是十六进制颜色代码
texts
array[object (组件-文本) {11}] 
可选
x
integer 
文本 X 坐标
必需
y
integer 
文本 Y 坐标
必需
text
string 
文本内容
必需
width
integer 
文本宽度
必需
文本宽度决定了文本的最大显示宽度,当文字内容超过宽度,会自动换行
font
enum<string> 
字体
可选
更多可用字体请查看 https://www.imgrender.net/docs/dev/api/generate-image#字体
枚举值:
SourceHanSansSC-Normal
默认值:
SourceHanSansSC-Normal
fontSize
integer 
文字大小
可选
单位为 pt
lineHeight
integer 
文本行高
可选
不能小于fontSize
lineSpacing
integer 
行距倍数
可选
lineSpacing * fontSize = lineHeight
默认值:
1
color
string 
文本颜色
可选
格式为十六进制颜色代码
默认值:
#000000
textAlign
enum<string> 
文本水平对齐方式
可选
可选值有:left、center、right
枚举值:
leftcenterright
zIndex
integer 
渲染层级
可选
相当于指定图层,会影响同一位置不同内容的覆盖情况
默认值:
0
images
array[object (组件-图片) {13}] 
可选
x
integer 
图片 X 坐标
必需
y
integer 
图片 Y 坐标
必需
width
integer 
图片渲染宽度
必需
用于缩放图片
height
integer 
图片渲染高度
必需
用于缩放图片
url
string 
图片链接
必需
需要保证图片能够正常访问下载。支持的图片格式:gif、jpeg、png、bmp、tiff、webp
borderColor
string 
边框颜色
可选
四个边均相同
默认值:
#000000
borderWidth
integer 
边框宽度
可选
默认边框宽度一半在内部,一半在外。暂不支持调整
>= 0
默认值:
0
borderRadius
integer 
四个顶点圆角半径
可选
>= 0
默认值:
0
borderTopLeftRadius
integer 
左上角顶点圆角半径
可选
优先级高于 borderRadius
>= 0
默认值:
0
borderTopRightRadius
integer 
右上角顶点圆角半径
可选
优先级高于 borderRadius
>= 0
默认值:
0
borderBottomLeftRadius
integer 
左下角顶点圆角半径
可选
优先级高于 borderRadius
>= 0
默认值:
0
borderBottomRightRadius
integer 
右下角顶点圆角半径
可选
优先级高于 borderRadius
>= 0
默认值:
0
zIndex
integer 
渲染层级
可选
会影响同一位置不同内容的覆盖情况
lines
array[object (组件-直线) {7}] 
可选
startX
integer 
起点 X 坐标
必需
startY
integer 
起点 Y 坐标
必需
endX
integer 
终点 X 坐标
必需
endY
integer 
终点 Y 坐标
必需
width
integer 
宽度
必需
color
string 
颜色
可选
必须为十六进制颜色代码
默认值:
#000000
zIndex
integer 
渲染层级
可选
默认值:
0
qrcodes
array[object (组件-二维码) {7}] 
可选
x
integer 
二维码 X 坐标
必需
y
integer 
二维码 Y 坐标
必需
size
integer 
正方形二维码尺寸大小
必需
content
string 
二维码内容
必需
foregroundColor
string 
二维码前景色
可选
必须为十六进制颜色代码
backgroundColor
string 
二维码背景色
可选
必须为十六进制颜色代码
默认值:
#ffffff
zIndex
integer 
渲染层级
可选
会影响同一位置不同内容的覆盖情况
blocks
array[object (组件-矩形) {13}] 
可选
x
integer 
矩形 X 坐标
必需
y
integer 
矩形 Y 坐标
必需
width
integer 
矩形宽度
必需
height
integer 
矩形高度
必需
backgroundColor
string 
背景颜色
可选
默认值:
#000000
borderColor
string 
边框颜色
可选
四个边均相同
默认值:
#000000
borderWidth
integer 
边框宽度
可选
默认边框宽度一半在内部,一半在外。暂不支持调整
>= 0
默认值:
0
borderRadius
integer 
四个顶点圆角半径
可选
>= 0
默认值:
0
borderTopLeftRadius
integer 
左上角顶点圆角半径
可选
优先级高于 borderRadius
>= 0
默认值:
0
borderTopRightRadius
integer 
右上角顶点圆角半径
可选
优先级高于 borderRadius
>= 0
默认值:
0
borderBottomLeftRadius
integer 
左下角顶点圆角半径
可选
优先级高于 borderRadius
>= 0
默认值:
0
borderBottomRightRadius
integer 
右下角顶点圆角半径
可选
优先级高于 borderRadius
>= 0
默认值:
0
zIndex
integer 
渲染层级
可选
会影响同一位置不同内容的覆盖情况
>= 0
默认值:
0
borderColor
string 
边框颜色
可选
四个边均相同
默认值:
#000000
borderWidth
integer 
边框宽度
可选
默认边框宽度一半在内部,一半在外。暂不支持调整
>= 0
默认值:
0
borderRadius
integer 
四个顶点圆角半径
可选
>= 0
默认值:
0
borderTopLeftRadius
integer 
左上角顶点圆角半径
可选
优先级高于 borderRadius
>= 0
默认值:
0
borderTopRightRadius
integer 
右上角顶点圆角半径
可选
优先级高于 borderRadius
>= 0
默认值:
0
borderBottomLeftRadius
integer 
左下角顶点圆角半径
可选
优先级高于 borderRadius
>= 0
默认值:
0
borderBottomRightRadius
integer 
右下角顶点圆角半径
可选
优先级高于 borderRadius
>= 0
默认值:
0
示例
{
    "width": 640,
    "height": 1050,
    "backgroundColor": "#d75650",
    "blocks": [
        {
            "x": 15,
            "y": 268,
            "width": 610,
            "height": 770,
            "backgroundColor": "#fff",
            "borderColor": "#fff"
        }
    ],
    "texts": [
        {
            "x": 320,
            "y": 185,
            "text": "Davinci Li",
            "font": "jiangxizhuokai",
            "fontSize": 22,
            "color": "#fff",
            "width": 320,
            "textAlign": "center",
            "zIndex": 1
        },
        {
            "x": 320,
            "y": 220,
            "text": "邀请你来参加抽奖",
            "font": "jiangxizhuokai",
            "fontSize": 22,
            "color": "#fff",
            "width": 320,
            "textAlign": "center",
            "zIndex": 1
        },
        {
            "x": 30,
            "y": 640,
            "text": "奖品: 本田-CB650R 摩托车",
            "font": "jiangxizhuokai",
            "fontSize": 22,
            "color": "#000",
            "width": 580,
            "textAlign": "left",
            "zIndex": 1
        },
        {
            "x": 30,
            "y": 676,
            "text": "01 月 31 日 18:00 自动开奖",
            "font": "jiangxizhuokai",
            "fontSize": 18,
            "color": "#9a9a9a",
            "width": 580,
            "textAlign": "left",
            "zIndex": 1
        },
        {
            "x": 320,
            "y": 960,
            "text": "长按识别二维码,参与抽奖",
            "font": "jiangxizhuokai",
            "fontSize": 22,
            "color": "#9a9a9a",
            "width": 580,
            "textAlign": "center",
            "zIndex": 1
        }
    ],
    "lines": [
        {
            "startX": 30,
            "startY": 720,
            "endX": 610,
            "endY": 720,
            "width": 1,
            "color": "#E1E1E1",
            "zIndex": 1
        }
    ],
    "images": [
        {
            "x": 248,
            "y": 25,
            "width": 120,
            "height": 120,
            "url": "https://img-chengxiaoli-1253325493.cos.ap-beijing.myqcloud.com/bikers_327390-13.jpg",
            "borderRadius": 60,
            "zIndex": 1
        },
        {
            "x": 108,
            "y": 285,
            "width": 400,
            "height": 300,
            "url": "https://img-chengxiaoli-1253325493.cos.ap-beijing.myqcloud.com/cb650R.jpeg",
            "zIndex": 1
        }
    ],
    "qrcodes": [
        {
            "x": 208,
            "y": 726,
            "size": 200,
            "content": "http://weixin.qq.com/r/yRzk-JbEbMsTrdKf90nb",
            "foregroundColor": "#000",
            "backgroundColor": "#fff",
            "zIndex": 1
        }
    ]
}

示例代码

Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://api.imgrender.net/open/v1/pics' \
--header 'X-API-Key: 请替换为你的应用密钥' \
--header 'Content-Type: application/json' \
--data-raw '{
    "width": 640,
    "height": 1050,
    "backgroundColor": "#d75650",
    "blocks": [
        {
            "x": 15,
            "y": 268,
            "width": 610,
            "height": 770,
            "backgroundColor": "#fff",
            "borderColor": "#fff"
        }
    ],
    "texts": [
        {
            "x": 320,
            "y": 185,
            "text": "Davinci Li",
            "font": "jiangxizhuokai",
            "fontSize": 22,
            "color": "#fff",
            "width": 320,
            "textAlign": "center",
            "zIndex": 1
        },
        {
            "x": 320,
            "y": 220,
            "text": "邀请你来参加抽奖",
            "font": "jiangxizhuokai",
            "fontSize": 22,
            "color": "#fff",
            "width": 320,
            "textAlign": "center",
            "zIndex": 1
        },
        {
            "x": 30,
            "y": 640,
            "text": "奖品: 本田-CB650R 摩托车",
            "font": "jiangxizhuokai",
            "fontSize": 22,
            "color": "#000",
            "width": 580,
            "textAlign": "left",
            "zIndex": 1
        },
        {
            "x": 30,
            "y": 676,
            "text": "01 月 31 日 18:00 自动开奖",
            "font": "jiangxizhuokai",
            "fontSize": 18,
            "color": "#9a9a9a",
            "width": 580,
            "textAlign": "left",
            "zIndex": 1
        },
        {
            "x": 320,
            "y": 960,
            "text": "长按识别二维码,参与抽奖",
            "font": "jiangxizhuokai",
            "fontSize": 22,
            "color": "#9a9a9a",
            "width": 580,
            "textAlign": "center",
            "zIndex": 1
        }
    ],
    "lines": [
        {
            "startX": 30,
            "startY": 720,
            "endX": 610,
            "endY": 720,
            "width": 1,
            "color": "#E1E1E1",
            "zIndex": 1
        }
    ],
    "images": [
        {
            "x": 248,
            "y": 25,
            "width": 120,
            "height": 120,
            "url": "https://img-chengxiaoli-1253325493.cos.ap-beijing.myqcloud.com/bikers_327390-13.jpg",
            "borderRadius": 60,
            "zIndex": 1
        },
        {
            "x": 108,
            "y": 285,
            "width": 400,
            "height": 300,
            "url": "https://img-chengxiaoli-1253325493.cos.ap-beijing.myqcloud.com/cb650R.jpeg",
            "zIndex": 1
        }
    ],
    "qrcodes": [
        {
            "x": 208,
            "y": 726,
            "size": 200,
            "content": "http://weixin.qq.com/r/yRzk-JbEbMsTrdKf90nb",
            "foregroundColor": "#000",
            "backgroundColor": "#fff",
            "zIndex": 1
        }
    ]
}'

返回响应

🟢200成功
application/json
Body
code
integer 
错误码
必需
当错误码为 0 时,表示处理成功,其他值表示存在一定的问题
message
string 
提示信息
必需
用于解释错误原因
data
object 
返回的数据
可选
只在错误码为 0 时返回
url
string 
生成的图片的访问链接
必需
出于安全考虑,链接只有 5 分钟有效期
示例
{
    "code": 0,
    "message": "ok",
    "data": {
        "url": "https://davinci.imgrender.cn/6e31cfcd683a36d0522a8cc34e244379.jpg?sign=xxx"
    }
}
修改于 2023-08-15 10:07:08
上一页
状态码与错误码
Built with