# Technical support (/docs/contact-us)
To stay in closer touch with customers and improve the product more efficiently, we run a customer group. If you hit a problem or have a suggestion, scan the code and talk with us.
Online support [#online-support]
You can also click the chat window in the bottom-right corner of the site, or the button below, to talk with us directly. During business hours we reply as soon as we can.
WeChat [#wechat]
Add us on WeChat and include this note: "imgrender"
# Before you integrate (/docs/api/basic)
Base URL [#base-url]
The imgrender API is organized around REST. Our API has predictable, resource-oriented URLs.
Every imgrender API uses this base URL:
```bash
https://api.imgrender.com/open/
```
Recommended APIs [#recommended-apis]
For production, use the [Generate image from template API](/docs/api/generate-image-by-template "Generate image from template API"): design and publish a template in the [template editor](/playground "Open the template editor"), then pass variables to generate an image.
To pass complete HTML on every request without a saved template, use the [Generate image from HTML API](/docs/api/generate-image "Generate image from HTML API").
To generate a static QR code, use the [QR code API](/qrcode-api "QR code API"): it returns PNG, SVG, or Base64 directly from the URL query, with no authentication.
Data format [#data-format]
The `Content-Type` header of every HTTP request is `application/json`.
Every request and response body is `JSON`.
Request URLs and request bodies are case-sensitive.
Authentication [#authentication]
imgrender authenticates requests with an `API Key`. Add this authentication field to the header of every request:
```
X-API-Key: your API key
```
See [API keys](/docs/dashboard/api-key "View the API key management docs") for how to get an API key.
Versioning [#versioning]
imgrender uses semantic version numbers for the API, such as `v1` and `v2`.
The version number is in the URL path. A full URL that includes the version looks like this:
```
https://api.imgrender.com/open/v1/
```
imgrender tries to keep the API compatible:
* If an API change is compatible, the API version number stays the same.
* If an API change is not compatible, a new version number is added and the previous API version is kept for a period of time. For example: `v1 -> v2`
# Generate image from template (recommended) (/docs/api/generate-image-by-template)
With this API, you can use a template created and published in the imgrender dashboard or the [template editor](/playground "Open the template editor"), pass variable values, and synchronously generate an image. The server loads the template content, validates the variables, finishes rendering, and returns a CDN URL for the image.
This is the recommended way to call the API in production: design and publish the template in the template editor, then pass only variables in the request. You do not need to submit complete HTML every time.
If you have not created a template yet, start with [Quick start](/docs "Quick start") and the [template guide](/docs/template-guide/overview "Template guide"). See [Variables](/docs/template-guide/variables "Variables") for how to write variables.
Request [#request]
Request method and URL [#request-method-and-url]
```
POST https://api.imgrender.com/open/v1/images/templates/{id}/render
```
`{id}` is the template ID. You can find it on the template details page in the dashboard.
Header parameters [#header-parameters]
| Field | Type | Required | Description |
| :----------: | :----: | :------: | ---------------------------------------------------------------------------------------------- |
| X-API-Key | string | yes | Used to authorize the request. See [Authentication](/docs/api/basic "View API authentication") |
| Content-Type | string | yes | **Fixed value**: "application/json; charset=utf-8" |
Path parameters [#path-parameters]
| Field | Type | Required | Description |
| ----- | :----: | :------: | ----------------------------- |
| `id` | string | **yes** | Template ID (set in the path) |
Request body parameters [#request-body-parameters]
| Field | Type | Required | Description | Default |
| ----------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------- |
| `variables` | `object` | **yes** | Map of variable names to values. Variables defined in the template are replaced by name. Variables that are not defined are ignored. | - |
| `width` | `number` | no | Override the template's default output width, in pixels. | - |
| `height` | `number` | no | Override the template's default output height, in pixels. | - |
| `format` | `string` | no | Override the template's default output format. Allowed values are `png`, `jpeg`, and `webp`. | - |
| `quality` | `number` | no | Override the template's default image quality (0-100). Applies only to `jpeg` and `webp`. | - |
| `useDraft` | `boolean` | no | Whether to render draft content. Published content is used by default. Use draft content only while debugging. | `false` |
* The template must be published first. If it is not published or has been archived, the API returns `409`.
* To pass complete HTML on every request without a saved template, use the [Generate image from HTML API](/docs/api/generate-image "Generate image from HTML API").
Response [#response]
When the request succeeds, the HTTP status code is `200` and data is returned as JSON:
```json
{
"code": 0,
"message": "ok",
"data": {
"url": "https://res.imgrender.com/6e31cfcd683a36d0522a8cc34e244379.jpg?sign=xxx"
}
}
```
* `code`: The error code. `0` means the request succeeded; any other value indicates a problem.
* `message`: A message corresponding to `code`. For more messages, see [Status codes and error codes](/docs/api/status-code "Status codes and error codes").
* `data`: The returned data, present when `code` is `0`. `url` is the image URL. The image URL **is valid for 5 minutes**, so download or display the image promptly. After it expires, send the request again to get a new URL.
Example [#example]
Below is a complete request example that shows how to pass variables for a template ID and generate an image:
```bash
curl -X POST https://api.imgrender.com/open/v1/images/templates/:template_id/render \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_API_KEY" \
-d '{
"variables": {
"title": "Weekend raffle",
"nickname": "Davinci",
"avatar": "https://example.com/avatar.jpg"
},
"format": "png",
"quality": 90
}'
```
```javascript
const payload = {
variables: {
title: 'Weekend raffle',
nickname: 'Davinci',
avatar: 'https://example.com/avatar.jpg',
},
format: 'png',
quality: 90,
}
fetch(
'https://api.imgrender.com/open/v1/images/templates/:template_id/render',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'YOUR_API_KEY',
},
body: JSON.stringify(payload),
},
)
.then((res) => res.json())
.then((result) => console.log('Image URL:', result.data.url))
```
Error codes [#error-codes]
| Error code | HTTP status code | Description | Suggested action |
| ---------- | ---------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| `10103` | `400` | Invalid parameters or variable validation failed | Check request parameters such as `variables` against the message. |
| `10104` | `401` | API key authentication failed | Check that the API key is set correctly and is still valid. |
| `20105` | `403` | Image generation failed | Follow the message. A common cause is a template rendering error. |
| `30101` | `403` | No credits available | Check that your credits are sufficient and have not expired. |
| - | `409` | The template is not published, has been archived, or the draft is unavailable | Confirm that the template is published, or turn off `useDraft` and retry. |
For more common error codes, see [Status codes and error codes](/docs/api/status-code "Status codes and error codes").
# Blueprint - describe image content (/docs/api/generate-image-v1/blueprint)
The "blueprint" is the content protocol used only by the legacy API. It no longer receives new features.
We strongly recommend migrating to the [Generate image from template API](/docs/api/generate-image-by-template "Generate image from template API"). Design your template in HTML and define variables in the [template editor](/playground "Open the template editor"); once it's published, you only need to pass in variables to generate images:
* **HTML-based templates**: Use the familiar tag structure of front-end development instead of the complex "blueprint" JSON protocol.
* **Modern styling**: Full support for inline styles (`style`) and Tailwind CSS classes for quick layout.
* **Variables and conditional rendering**: Reduce the data you need to send with each request.
* **Multiple export formats**: Export high-quality images as WebP, PNG, or JPEG.
imgrender can describe image content with a specific JSON document. We call that document a blueprint. The blueprint determines how an image is rendered and what the image contains.
The properties and structure of a blueprint are described below.
Blueprint [#blueprint]
A blueprint fully describes the image dimensions and the content in the image. The properties are:
| Field name | Data type | Default | Required | Description |
| :---------------------: | :------------: | :-----: | :------: | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| width | int | | yes | Image width. Content cannot exceed this width. **Maximum 1100**. |
| height | int | | yes | Image height. Content cannot exceed this height. **Maximum 2480**. |
| backgroundColor | Hex Color Code | | yes | Image background color. Must be a hexadecimal color code. |
| borderColor | Hex Color Code | #000000 | | Color of the four borders. |
| borderWidth | int | 0 | | Width of the four borders. Half of the border width lies inside and half lies outside. This split cannot be adjusted yet. |
| borderRadius | int | 0 | | Corner radius of the four border corners. |
| borderTopLeftRadius | int | 0 | | Corner radius of the top-left border corner. Takes priority over `borderRadius`. |
| borderTopRightRadius | int | 0 | | Corner radius of the top-right border corner. Takes priority over `borderRadius`. |
| borderBottomLeftRadius | int | 0 | | Corner radius of the bottom-left border corner. Takes priority over `borderRadius`. |
| borderBottomRightRadius | int | 0 | | Corner radius of the bottom-right border corner. Takes priority over `borderRadius`. |
| texts | Array | \[] | | Text in the image. See [Text](/docs/api/generate-image-v1/blueprint#text "Text"). |
| images | Array | \[] | | Images in the picture. An external image can be rendered onto the new image. See [Image](/docs/api/generate-image-v1/blueprint#image "Image"). |
| lines | Array | \[] | | Lines in the image, useful as dividers. See [Line](/docs/api/generate-image-v1/blueprint#line "Line"). |
| qrcodes | Array | \[] | | QR codes in the image. A QR code can be rendered on the image. See [QR code](/docs/api/generate-image-v1/blueprint#qr-code "QR code"). |
| blocks | Array | \[] | | Rectangles in the image. See [Rectangle](/docs/api/generate-image-v1/blueprint#rectangle "Rectangle"). |
Example [#example]
```
{
"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": "You're invited to join the giveaway",
"font": "jiangxizhuokai",
"fontSize": 22,
"color": "#fff",
"width": 320,
"textAlign": "center",
"zIndex": 1
},
{
"x": 30,
"y": 640,
"text": "Prize: Honda CB650R motorcycle",
"font": "jiangxizhuokai",
"fontSize": 22,
"color": "#000",
"width": 580,
"textAlign": "left",
"zIndex": 1
},
{
"x": 30,
"y": 676,
"text": "Automatic drawing at 18:00 on January 31",
"font": "jiangxizhuokai",
"fontSize": 18,
"color": "#9a9a9a",
"width": 580,
"textAlign": "left",
"zIndex": 1
},
{
"x": 320,
"y": 960,
"text": "Press and hold the QR code to join the giveaway",
"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
}
]
}
```
The components that describe image content are covered below.
Coordinate system [#coordinate-system]
Before the individual components, you need the coordinate system. It controls where elements are placed on the image.
imgrender uses this coordinate system:
* The top-left corner is the `global origin (0,0)`.
* The X axis runs from left to right, and the Y axis runs from top to bottom.
* The unit is pixels (px).
Text [#text]
The text component adds text to an image.
The properties are:
Properties [#properties]
| Field name | Data type | Default | Required | Description |
| :---------: | :-------: | :--------------------: | :------: | --------------------------------------------------------------------------------------------- |
| x | int | | yes | Text X coordinate. |
| y | int | | yes | Text Y coordinate. |
| text | string | | yes | Text content. |
| width | int | | yes | Text width. Sets the maximum display width. Text that exceeds this width wraps automatically. |
| font | string | SourceHanSansSC-Normal | | Font used to render the text. See [Font](#font "Font"). |
| fontSize | int | 18 | | Font size, in pt. |
| lineHeight | int | Base font height | | Line height. Cannot be smaller than `fontSize`. |
| lineSpacing | float | 1 | | Line-spacing multiplier. `lineSpacing * fontSize = lineHeight`. |
| color | Array | #000000 | | Text color. |
| textAlign | string | `left` | | Horizontal alignment. Allowed values: `left`, `center`, and `right`. |
| zIndex | int | 0 | | Stacking order. Affects how content in the same position covers other content. |
Anchor [#anchor]
The `textAlign` property affects the text anchor.
As shown in the figure above, the dashed box is the display width and line height of the text.
For the text `Prize: Honda CB650R`, `textAlign` is `left`, so the anchor is at the top-left corner of the text.
For the text `Press and hold the QR code to join the giveaway`, `textAlign` is `center`, so the anchor is at the top center of the text.
For the text `Davinci Li`, `textAlign` is `right`, so the anchor is at the top-right corner of the text.
Font [#font]
Custom fonts are not supported yet. imgrender currently provides the following fonts, which are free for commercial use:
To add more fonts that are free for commercial use, contact the developer.
| Font name | Name |
| --------------------------- | :----------------------------: |
| jiangxizhuokai | Jiangxi Zhuokai |
| slideyouran | Slide Youran Xiaokai |
| SourceHanSansSC-Heavy | Source Han Sans SC Heavy |
| SourceHanSansSC-Bold | Source Han Sans SC Bold |
| SourceHanSansSC-Medium | Source Han Sans SC Medium |
| SourceHanSansSC-Regular | Source Han Sans SC Regular |
| SourceHanSansSC-Normal | Source Han Sans SC Normal |
| SourceHanSansSC-Light | Source Han Sans SC Light |
| SourceHanSansSC-ExtraLight | Source Han Sans SC ExtraLight |
| SourceHanSerifCN-Heavy | Source Han Serif CN Heavy |
| SourceHanSerifCN-Bold | Source Han Serif CN Bold |
| SourceHanSerifCN-SemiBold | Source Han Serif CN SemiBold |
| SourceHanSerifCN-Medium | Source Han Serif CN Medium |
| SourceHanSerifCN-Regular | Source Han Serif CN Regular |
| SourceHanSerifCN-Light | Source Han Serif CN Light |
| SourceHanSerifCN-ExtraLight | Source Han Serif CN ExtraLight |
| Alibaba-PuHuiTi-Heavy | Alibaba PuHuiTi Heavy |
| Alibaba-PuHuiTi-Bold | Alibaba PuHuiTi Bold |
| Alibaba-PuHuiTi-Medium | Alibaba PuHuiTi Medium |
| Alibaba-PuHuiTi-Regular | Alibaba PuHuiTi Regular |
| Alibaba-PuHuiTi-Light | Alibaba PuHuiTi Light |
Example [#example-1]
```json
{
"x": 320,
"y": 185,
"text": "Davinci Li",
"font": "SourceHanSansSC-Normal",
"fontSize": 22,
"color": "#fff",
"width": 320,
"textAlign": "center"
}
```
Image [#image]
The image component adds an image to the picture, for example a custom background.
The image URL must be accessible so the file can be downloaded.
Supported image formats: gif, jpeg, png, bmp, tiff, and webp.
Properties [#properties-1]
| Field name | Data type | Default | Required | Description |
| :---------------------: | :------------: | :------: | :------: | ------------------------------------------------------------------------------------------------------------- |
| x | int | | yes | Image X coordinate. |
| y | int | | yes | Image Y coordinate. |
| url | url | | yes | Image URL. The image must be accessible for download. Supported formats: gif, jpeg, png, bmp, tiff, and webp. |
| width | int | | yes | Rendered width, used to scale the image. |
| height | int | | yes | Rendered height, used to scale the image. |
| borderColor | Hex Color Code | #000000 | | Color of the four borders. |
| borderWidth | int | 0 | | Width of the four borders. |
| strokeAlign | string | `CENTER` | | Border alignment. Allowed values: `CENTER` (center), `INSIDE` (inside), and `OUTSIDE` (outside). |
| borderRadius | int | 0 | | Corner radius of the four border corners. |
| borderTopLeftRadius | int | 0 | | Corner radius of the top-left border corner. Takes priority over `borderRadius`. |
| borderTopRightRadius | int | 0 | | Corner radius of the top-right border corner. Takes priority over `borderRadius`. |
| borderBottomLeftRadius | int | 0 | | Corner radius of the bottom-left border corner. Takes priority over `borderRadius`. |
| borderBottomRightRadius | int | 0 | | Corner radius of the bottom-right border corner. Takes priority over `borderRadius`. |
| zIndex | int | 0 | | Stacking order. Affects how content in the same position covers other content. |
Example [#example-2]
```json
{
"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
}
```
Line [#line]
The line component adds a line to an image. Use it to draw dividers, underlines, and similar marks.
Properties [#properties-2]
| Field name | Data type | Default | Required | Description |
| :--------: | :------------: | :-----: | :------: | ------------------- |
| startX | int | | yes | Start X coordinate. |
| startY | int | | yes | Start Y coordinate. |
| endX | int | | yes | End X coordinate. |
| endY | int | | yes | End Y coordinate. |
| width | int | | yes | Line width. |
| color | Hex Color Code | #000000 | | Line color. |
| zIndex | int | 0 | | Stacking order. |
Example [#example-3]
```json
{
"startX": 30,
"startY": 696,
"endX": 610,
"endY": 696,
"width": 1,
"color": "#E1E1E1",
"zIndex": 1
}
```
Rectangle [#rectangle]
The rectangle component adds a rectangle to an image.
Properties [#properties-3]
| Field name | Data type | Default | Required | Description |
| :---------------------: | :------------: | :------: | :------: | ------------------------------------------------------------------------------------------------ |
| x | int | | yes | Rectangle X coordinate. |
| y | int | | yes | Rectangle Y coordinate. |
| width | int | | yes | Rectangle width. |
| height | int | | yes | Rectangle height. |
| backgroundColor | Hex Color Code | #000000 | | Background color. |
| borderColor | Hex Color Code | #000000 | | Color of the four borders. |
| borderWidth | int | 0 | | Width of the four borders. |
| strokeAlign | string | `CENTER` | | Border alignment. Allowed values: `CENTER` (center), `INSIDE` (inside), and `OUTSIDE` (outside). |
| borderRadius | int | 0 | | Corner radius of the four border corners. |
| borderTopLeftRadius | int | 0 | | Corner radius of the top-left border corner. Takes priority over `borderRadius`. |
| borderTopRightRadius | int | 0 | | Corner radius of the top-right border corner. Takes priority over `borderRadius`. |
| borderBottomLeftRadius | int | 0 | | Corner radius of the bottom-left border corner. Takes priority over `borderRadius`. |
| borderBottomRightRadius | int | 0 | | Corner radius of the bottom-right border corner. Takes priority over `borderRadius`. |
| zIndex | int | 0 | | Stacking order. Affects how content in the same position covers other content. |
Example [#example-4]
```json
{
"x": 220,
"y": 100,
"width": 380,
"height": 200,
"backgroundColor": "#fff",
"borderColor": "#fff"
}
```
QR code [#qr-code]
The QR code component adds a QR code to an image, for example a QR code for a share link.
Parameters [#parameters]
| Field name | Data type | Default | Required | Description |
| :-------------: | :------------: | :-----: | :------: | ------------------------------------------------------------------------------ |
| x | int | | yes | QR code X coordinate. |
| y | int | | yes | QR code Y coordinate. |
| size | int | | yes | Size of the square QR code. |
| content | string | | yes | QR code content. |
| foregroundColor | Hex Color Code | #000000 | | QR code foreground color. |
| backgroundColor | Hex Color Code | #ffffff | | QR code background color. |
| zIndex | int | 0 | | Stacking order. Affects how content in the same position covers other content. |
The QR code component has a border in the background color, such as the white border around the QR code in the figure above. Border thickness is determined by both the QR code size and the length of the encoded content. For example, when `size` is 200px but the encoded content is only the character `a`, the border is wider than in the figure above. Set the QR code background color to the same color as the surrounding area to remove the effect of that border.
Example [#example-5]
```json
{
"x": 208,
"y": 726,
"size": 200,
"content": "http://weixin.qq.com/r/yRzk-JbEbMsTrdKf90nb",
"foregroundColor": "#000",
"backgroundColor": "#fff",
"zIndex": 1
}
```
# Design images with Figma (/docs/api/generate-image-v1/figma-plugin)
This plugin is only for the legacy API and no longer receives new features.
We strongly recommend migrating to the [Generate image from template API](/docs/api/generate-image-by-template "Generate image from template API"). Design your template in HTML and define variables in the [template editor](/playground "Open the template editor"); once it's published, you only need to pass in variables to generate images:
* **HTML-based templates**: Use the familiar tag structure of front-end development instead of the complex "blueprint" JSON protocol.
* **Modern styling**: Full support for inline styles (`style`) and Tailwind CSS classes for quick layout.
* **Variables and conditional rendering**: Reduce the data you need to send with each request.
* **Multiple export formats**: Export high-quality images as WebP, PNG, or JPEG.
imgrender blueprints have many parameters, which makes them complex to configure.
That's why we provide a Figma plugin: you can design an image in Figma and then use the plugin to export the design to an imgrender blueprint in one click.
How to install the plugin [#how-to-install-the-plugin]
To use the Figma plugin, you need to [create a Figma account](https://help.figma.com/hc/en-us/articles/360039811114 "Figma help center"). Then install the plugin:
1. Open the [imgrender Figma plugin page](https://www.figma.com/community/plugin/1273461051550664878 "imgrender Figma plugin page").
2. Click Try it out. This redirects you to a new Figma design file and opens the plugin preview dialog.
3. Click the "Save" icon to save the plugin.
4. Click the "Run" button to run the plugin.
How to use the plugin [#how-to-use-the-plugin]
1. After you run the plugin, its UI is displayed.
2. Design your image in Figma.
3. Select the design.
4. Click the "Output" button in the plugin UI. The design is converted to an imgrender blueprint and copied to your clipboard automatically.
Notes [#notes]
1. The plugin requires the selection to be a single layer. Before exporting, group the elements of your design.
2. The plugin currently supports these Figma elements: rectangles, lines, text, and images. QR code elements still need to be added to the blueprint manually.
3. Borders of rectangles and images only support sharp (mitered) corners.
4. Images can't be retrieved from Figma directly yet. When exporting, the `url` of image elements is always set to `Please replace with accessible image url`. After exporting, replace it with the corresponding image URL.
5. Text currently only supports the Source Han Sans SC font family. If you choose another font, it will be exported as `SourceHanSansSC-Normal`. After exporting, replace it with the font you want.
# Generate image from JSON (legacy) (/docs/api/generate-image-v1)
This API (the legacy blueprint API) no longer receives new features.
We strongly recommend migrating to the [Generate image from template API](/docs/api/generate-image-by-template "Generate image from template API"). Design your template in HTML and define variables in the [template editor](/playground "Open the template editor"); once it's published, you only need to pass in variables to generate images:
* **HTML-based templates**: Use the familiar tag structure of front-end development instead of the complex "blueprint" JSON protocol.
* **Modern styling**: Full support for inline styles (`style`) and Tailwind CSS classes for quick layout.
* **Variables and conditional rendering**: Reduce the data you need to send with each request.
* **Multiple export formats**: Export high-quality images as WebP, PNG, or JPEG.
Synchronously generates an image from the provided [blueprint](/docs/api/generate-image-v1/blueprint "Blueprint") and returns **a URL to access the image**.
With this API, the caller controls the blueprint in real time, which offers the most flexibility.
[Debug online and view the interactive API docs](https://apifox.com/apidoc/project-2058619/api-81628036 "Open the Apifox API docs")
Request [#request]
* **HTTP URL**: `https://api.imgrender.com/open/v1/pics`
* **HTTP Method**: POST
* **Version**: v1
Request parameters [#request-parameters]
Header parameters [#header-parameters]
| Field | Type | Required | Description |
| :----------: | :----: | :------: | ---------------------------------------------------------------------------------------------- |
| X-API-Key | string | yes | Used to authorize the request. See [Authentication](/docs/api/basic "View API authentication") |
| Content-Type | string | yes | **Fixed value**: "application/json; charset=utf-8" |
Body parameters [#body-parameters]
The body must contain [blueprint](/docs/api/generate-image-v1/blueprint "View the blueprint docs") data and nothing else.
Response [#response]
When the request succeeds, the HTTP status code is `200` and data is returned as JSON:
```json
{
"code": 0,
"message": "ok",
"data": {
"url": "https://davinci.imgrender.cn/6e31cfcd683a36d0522a8cc34e244379.jpg?sign=xxx"
}
}
```
* `code`: The error code. `0` means the request succeeded; any other value indicates a problem.
* `message`: A message corresponding to `code`. For more messages, see [Status codes and error codes](/docs/api/status-code "Status codes and error codes").
* `data`: The returned data, present when `code` is `0`. `url` is the image URL. The image URL **is valid for 5 minutes**, so download or display the image promptly. After it expires, send the request again to get a new URL.
Error codes [#error-codes]
| Error code | HTTP status code | Description | Suggested action |
| ---------- | ---------------- | ----------------------- | -------------------------------------- |
| `20105` | `403` | Image generation failed | Follow the instructions in the message |
For more common error codes, see [Status codes and error codes](/docs/api/status-code "Status codes and error codes").
# Custom fonts (/docs/api/generate-image/custom-fonts)
imgrender includes fonts that are free for commercial use. Prefer the [built-in fonts](/docs/template-guide/typography-and-fonts "View the built-in font list"), which render faster.
This page explains how to pass custom fonts in the request body of the [Generate image from HTML API](/docs/api/generate-image "Generate image from HTML API").
If you use the recommended [Generate image from template API](/docs/api/generate-image-by-template "Generate image from template API"), configure fonts on the template in the [template editor](/playground "Open the template editor"). You do not need to pass `fonts` in the request.
The following explains how to use custom fonts in a request.
Load custom web fonts [#load-custom-web-fonts]
If your design needs a special font file, you can dynamically register custom fonts with the `fonts` array field in the [request body](/docs/api/generate-image#request-body-parameters "Request body parameters").
In the `fonts` array, you can pass objects with the following structure:
| Field | Type | Required | Description |
| ------------ | ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `familyName` | `string` | **yes** | Font family name. Only English letters (uppercase or lowercase) and digits are allowed. In `content`, reference this name with `fontFamily`, and the match must be exact. |
| `fontUrls` | `string[]` | **yes** | List of URLs to download the font files. Common formats such as TTF, OTF, and WOFF are supported. |
Notes:
The familyName property overrides the font name in the font file metadata, but properties such as weight and style still come directly from the font file metadata. Each object therefore corresponds to one font family. Every font file listed in its fontUrls should belong to that family, and each weight and style should be unique.
Example:
```
{
"content": ,
fonts: [
{
"fontFamily": "MyFont1",
"fontUrls": [
"https://example.com/MyFont1/Regular.ttf",
"https://example.com/MyFont1/Medium.ttf",
"https://example.com/MyFont1/SemiBold.ttf",
...
]
},
{
"fontFamily": "MyFont2",
"fontUrls": [
"https://example.com/MyFont2/Regular.ttf",
"https://example.com/MyFont2/Medium.ttf",
"https://example.com/MyFont2/SemiBold.ttf",
...
]
}
]
}
```
On-demand font loading [#on-demand-font-loading]
imgrender downloads and loads a custom font only when `content` actually references that font's `familyName` through `fontFamily`. Fonts that are not referenced are not loaded.
See [How to use fonts](/docs/template-guide/typography-and-fonts#using-fonts "How to use fonts").
1. Keep font files as small as possible. They must not exceed 10 MB. Files larger than 10 MB fail to load.
2. Make sure the URL is reachable on the public internet. If the service hosting your font has authentication enabled (for example, a private object storage service), the font URL must include the authentication information.
3. The URL must load quickly over the public internet.
# Generate image from HTML (/docs/api/generate-image)
For most use cases, use the [Generate image from template API](/docs/api/generate-image-by-template "Generate image from template API"): save and publish a template in the template editor, then pass only variables in the request.
This API is for one-off rendering when you do not save a template and pass complete HTML every time.
With this API, you can turn an HTML snippet directly into a high-quality image and export it as WebP, PNG, or JPEG.
Request [#request]
Request method and URL [#request-method-and-url]
```
POST https://api.imgrender.com/open/v1/images/render
```
Header parameters [#header-parameters]
| Field | Type | Required | Description |
| :----------: | :----: | :------: | ---------------------------------------------------------------------------------------------- |
| X-API-Key | string | yes | Used to authorize the request. See [Authentication](/docs/api/basic "View API authentication") |
| Content-Type | string | yes | **Fixed value**: "application/json; charset=utf-8" |
Request body parameters [#request-body-parameters]
| Field | Type | Required | Description | Default |
| --------- | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `content` | `string` | **yes** | HTML string that describes the image layout and content. See the [template guide](/docs/template-guide/overview "Template guide") for how to write it. | - |
| `width` | `number` | no | Width of the output image, in pixels. If omitted, the width adapts to the content. | - |
| `height` | `number` | no | Height of the output image, in pixels. If omitted, the height adapts to the content. | - |
| `format` | `string` | no | Output image format. `png`, `jpeg`, and `webp` are supported. | `webp` |
| `quality` | `number` | no | Image quality (0-100). Applies only to `jpeg` and `webp`. | - |
| `fonts` | `array` | no | List of custom font configurations, used to load and render external fonts in the content. See [Custom fonts](/docs/api/generate-image/custom-fonts "Custom fonts"). | `[]` |
Response [#response]
When the request succeeds, the HTTP status code is `200` and data is returned as JSON:
```json
{
"code": 0,
"message": "ok",
"data": {
"url": "https://res.imgrender.com/6e31cfcd683a36d0522a8cc34e244379.jpg?sign=xxx"
}
}
```
* `code`: The error code. `0` means the request succeeded; any other value indicates a problem.
* `message`: A message corresponding to `code`. For more messages, see [Status codes and error codes](/docs/api/status-code "Status codes and error codes").
* `data`: The returned data, present when `code` is `0`. `url` is the image URL. The image URL **is valid for 5 minutes**, so download or display the image promptly. After it expires, send the request again to get a new URL.
Example [#example]
Below is a complete request example that shows how to pass HTML and generate an image:
```bash
curl -X POST https://api.imgrender.com/open/v1/images/render \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_API_KEY" \
-d '{
"content": "
',
width: 800,
height: 400,
format: 'png',
}
fetch('https://api.imgrender.com/open/v1/images/render', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'YOUR_API_KEY',
},
body: JSON.stringify(payload),
})
.then((res) => res.json())
.then((result) => console.log('Image URL:', result.data.url))
```
To register custom web fonts in a request, see [Custom fonts](/docs/api/generate-image/custom-fonts "Custom fonts").
# Status codes and error codes (/docs/api/status-code)
HTTP status codes [#http-status-codes]
| HTTP status code | Description | Suggested action |
| ---------------- | --------------------- | ------------------------------------------------------------------------------------------------------------- |
| `200` | Success | |
| `400` | Request failed | This is usually because the request parameters are invalid. Check the request parameters against the message. |
| `401` | Authentication failed | Check that the API key is set correctly. |
| `403` | Request rejected | The server received the request, but rejected it because of a business restriction. Follow the message. |
| `404` | Resource not found | Check the request parameters. |
| `429` | Rate limited | Lower the request rate. |
| `500` | System error | Something went wrong on the server. Contact support. |
Common error codes [#common-error-codes]
The following are common error codes. Error codes specific to an API are documented on that API's page.
| Error code | HTTP status code | Description | Suggested action |
| ---------- | ---------------- | ---------------------- | ------------------------------------------------------------------------------- |
| `0` | `200` | Success | |
| `10101` | `500` | System error | Something went wrong on the server. Contact support. |
| `10102` | `429` | Rate limited | QPS is too high. Lower the request rate. |
| `10103` | `400` | Invalid parameters | Check the request parameters against the message. |
| `10104` | `401` | Authentication failed | Check that the API key is set correctly and is still valid. |
| `10105` | `403` | Operation forbidden | The request was rejected because of a business restriction. Follow the message. |
| `10106` | `403` | Duplicate operation | The request is a duplicate. Retry shortly. |
| `10107` | `404` | Resource not found | Check the request parameters. |
| `30101` | `403` | Insufficient resources | Check that the account has enough credits. |
Error response body [#error-response-body]
A failed response includes an `error` object in addition to `code` and `message`. A successful response does not include this field.
```json
{
"code": 10105,
"message": "Try again in 30 seconds",
"error": {
"name": "captcha.cooldown",
"params": { "seconds": 30 }
}
}
```
| Field | Type | Description |
| -------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `code` | integer | Error category. See the table above for values. |
| `message` | string | English error message that can be shown to users directly. |
| `error.name` | string | Stable error name, written as lowercase dot-separated English. Different scenarios under the same error code use different names. |
| `error.params` | object | Interpolation parameters for the message. Omitted when there are no parameters. |
When your code needs to branch by scenario, match `error.name`. Matching the `message` text is unreliable. Once published, an `error.name` keeps its meaning; the wording of `message` may change.
Common `error.name` values for the Open API:
| error.name | Error code | Description |
| -------------------------- | ---------- | ----------------------------------------------------------------- |
| `system.validation_failed` | `10103` | Request parameter validation failed. See `message` for details. |
| `apikey.missing` | `10104` | No API key was set. |
| `apikey.invalid_format` | `10104` | The API key format is invalid. |
| `apikey.invalid` | `10104` | The API key does not exist, or the key is incorrect. |
| `apikey.revoked` | `10104` | The API key is no longer valid. Replace it. |
| `credits.insufficient` | `30101` | Not enough credits are available. |
| `template.not_found` | `10107` | The template does not exist. |
| `template.not_published` | `10112` | The template is not published or has been archived. |
| `render.failed` | `20105` | Image rendering failed. |
| `blueprint.*` | `10103` | Blueprint parameter validation failed. See `message` for details. |
# API key management (/docs/dashboard/api-key)
Calls to imgrender must be authenticated with an API key. This page explains how to manage API keys.
Create an API key [#create-an-api-key]
After you sign in to the imgrender dashboard, click **API Keys** in the left sidebar to open API key management.
Click **"Create API key"**. The system generates a key for you.
The API key format is `number.random-string`.
Once it is created, you can call the [Generate image from template API](/docs/api/generate-image-by-template "Generate image from template API"). For the full setup, see [Quick start](/docs "Quick start").
Disable and delete [#disable-and-delete]
After you disable an API key, that API key can no longer call imgrender. Before you disable it, make sure your application is no longer using it.
You must disable an API key before you can delete it. After you delete it, you can no longer manage that API key. Proceed carefully.
API key rotation [#api-key-rotation]
To reduce the risk of stolen usage if an API key leaks, rotate API keys once a year. The replacement steps are:
1. Create a new API key
2. Replace the old API key with the new one in your application
3. Confirm the old API key is unused everywhere
4. Disable the old API key. It can no longer call the service
5. Delete the old API key
# Credit management (/docs/dashboard/credits)
After you sign in to the imgrender dashboard, click **Credits** in the left sidebar to open credit management.
Credits belong to the account. Every request under the same account can use them. Usage rules are in [Pricing](/docs/pricing "View pricing").
View the credit overview [#view-the-credit-overview]
The **Credit overview** at the top of the Credits page shows the account's current credits:
| Metric | Description |
| ----------------- | :--------------------------------------------------------------------------------: |
| Available credits | Credits that can be used for a request right now |
| Pending credits | Credits that have been issued but are not active yet |
| Expiring soon | Available credits that expire within the next 15 days |
| Next expiration | Expiration time of the soonest available credits, and how many credits expire then |
View credit records [#view-credit-records]
Each grant or purchase is its own record, with its own start time and expiration time.
Record statuses:
| Status | Description |
| ---------------- | :------------------------------------------------------: |
| Awaiting payment | A purchase was started and payment is not complete |
| Canceled | A purchase was started and then canceled before payment |
| Pending | The record is active, but the start time has not arrived |
| Active | Payment is complete and the credits can be used |
| Used up | The credits have not expired, but they are used up |
| Expired | The credits are not used up, but they have expired |
For 15 days after a purchase is started, unpaid records appear on the **Awaiting payment** tab. After 15 days they are canceled automatically. You can also cancel them yourself.
Buy credits [#buy-credits]
On the Credits page, click **Buy credits**, choose how many credits to buy, and pay for the order.
# Quick start (/docs)
Introduction [#introduction]
imgrender is a high-performance image generation service that lets your application generate images quickly. Use it for posters, certificates, product covers, blog covers, personalized ads, and more.
Recommended workflow: design a template in HTML and define variables in the [template editor](/playground "Open the template editor"), publish it, then call the [Generate image from template API](/docs/api/generate-image-by-template "Generate image from template API"). Pass in the variable values to generate an image.
Core features [#core-features]
Design a template in HTML and define variables in the template editor. When
your application calls the API, pass the template ID and variable values to
render a high-quality image (WebP, PNG, or JPEG). Inline styles and Tailwind
CSS classes are supported, so front-end developers can get started right away.
| Feature | Description |
| ---------------------- | -------------------------------------------------------------------------------------------------- |
| **Reusable templates** | Design a template once. Your application only sends variables, not a full HTML document each time |
| **Simple to use** | Pass a template ID and variables and get an image URL back. No rendering service to run |
| **High performance** | Server-side rendering with responses in milliseconds, without browser runtime overhead |
| **Flexible output** | Override size, format, and quality per request. Templates can use variables, conditions, and loops |
| **Rich styling** | Templates support inline styles and Tailwind CSS classes for complex layouts |
***
Get started [#get-started]
Start using imgrender in 3 steps:
1\. Sign up and get an API key [#1-sign-up-and-get-an-api-key]
Go to the imgrender dashboard, create an account, and sign in.
After you sign in, open the **API Keys** page and click "Create API key" to generate an API key. The format is `number.random-string`.
An API key authenticates calls to the service. Keep it private. Do not commit
it to a public repository or share it with anyone else.
2\. Create and publish a template [#2-create-and-publish-a-template]
Open the [template editor](/playground "Open the template editor"), write the template in HTML, and parameterize anything that should change with `{$ name $}`. Save and **publish** it, then copy the **template ID** from the template details page in the dashboard.
For how to write templates and use variables, see the [template guide](/docs/template-guide/overview "Template guide") and [Variables](/docs/template-guide/variables "Variables").
The live API uses published content by default. If the template is unpublished
or archived, the call returns `409`. To debug a draft, set `useDraft: true`
on the request.
3\. Call the API [#3-call-the-api]
Replace `YOUR_API_KEY` and `{template_id}` in the example below with your API key and template ID to generate an image:
```javascript
const response = await fetch(
'https://api.imgrender.com/open/v1/images/templates/{template_id}/render',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'YOUR_API_KEY',
},
body: JSON.stringify({
variables: {
title: 'Hello imgrender!',
},
format: 'png',
}),
},
)
const result = await response.json()
console.log('Image URL:', result.data.url)
```
```bash
curl -X POST 'https://api.imgrender.com/open/v1/images/templates/:template_id/render' \
-H 'Content-Type: application/json' \
-H 'X-API-Key: YOUR_API_KEY' \
-d '{
"variables": {
"title": "Hello imgrender!"
},
"format": "png"
}'
```
A successful response looks like this:
```json
{
"code": 0,
"message": "ok",
"data": {
"url": "https://res.imgrender.com/xxx.jpg?sign=xxx"
}
}
```
The returned image URL is valid for 5 minutes. Download or display the image
promptly. After it expires, send the request again to get a new URL.
To send the full HTML on every request without saving a template, use the
[Generate image from HTML API](/docs/api/generate-image "Generate image from HTML API").
In production, the template-based API is the better fit.
***
Next steps [#next-steps]
Learn layout, styling, variables, fonts, image loading, and more
Request parameters, how to pass variables, and error codes
# Pricing (/docs/pricing)
Credit usage [#credit-usage]
imgrender uses **credits** as the single billing resource. Each billable item consumes a set number of credits. Usage is listed below.
| Item | Cost | Notes |
| ---------------------------- | :------------------: | :----------------------------------------------------------------------: |
| Synchronous image generation | 1 credit per request | Charged only when the request succeeds. Failed requests are not charged. |
Free credits [#free-credits]
New accounts receive free credits at signup. The free allowance is listed below.
| Resource | Amount | How it is granted |
| -------- | :-------------------: | :---------------: |
| Credits | 100 credits at signup | One-time grant |
Buy credits [#buy-credits]
Buying credits, balances, and expiration are covered in [Credit management](/docs/dashboard/credits "View credit management").
| Resource | Billing | Price | Validity |
| -------- | :--------: | :---------------: | :------: |
| Credits | Per credit | ¥0.005 per credit | 365 days |
Example: buying 20000 credits:
* The total is 0.005 \* 20000 = ¥100.
* That covers 20000 synchronous image generation requests.
* Credits are valid for 365 days from the time payment completes.
How credits are applied [#how-credits-are-applied]
Credits are applied with these rules:
1. If the account has free credits, those are used first. Purchased credits are used after the free credits run out.
2. Credits closest to expiration are used first. When the expiration time is the same, credits that became active earlier are used first.
3. If there are not enough available credits, the request fails immediately. Buy more credits before you run out.
Refund policy [#refund-policy]
* For a given account, **unexpired, unused** credits can be refunded.
* Once used, credits cannot be refunded or extended.
* If a refund looks abnormal or abusive, imgrender may deny the request.
> Self-service refunds are not available yet. To request a refund, contact support.
FAQ [#faq]
1. Do you provide invoices?
> Yes. Electronic invoices are available. To request an invoice, contact support.
# Layout (/docs/template-guide/layout)
imgrender supports CSS Flexbox and Grid layouts.
Box model [#box-model]
In imgrender, every element follows the standard CSS box model. An element's total size is calculated from its content, padding, border, and margin.
Automatic width and height [#automatic-width-and-height]
imgrender can size the image to its content. You can also set the template width and height in the template editor, or override them with request parameters when calling the [Generate image from template API](/docs/api/generate-image-by-template "Generate image from template API"), to constrain the width and height of the generated image.
Image dimensions [#image-dimensions]
By default, an image is rendered at its original size. Set width and height to choose the rendered size.
```html
```
# Load images (/docs/template-guide/load-images)
Remote images [#remote-images]
imgrender can load remote images with the `img` tag and the CSS properties `background-image` and `mask-image`.
Supported image formats: `jpeg`, `png`, `webp`, and `svg`.
1. Keep image files as small as possible. The maximum size is 10 MB. Files larger than 10 MB fail to load.
2. The image URL must be reachable on the public internet. If the service hosting your images requires authentication (for example, a private object-storage bucket), the image URL must include the authentication parameters.
3. The image URL must load quickly over the public internet.
```html
```
```html
...
```
```html
...
```
Caching [#caching]
To improve rendering performance, imgrender caches images with the image URL as the key. When an image is loaded, a cache hit is used first and the image is not downloaded from the network again.
If imgrender has already cached the image for a URL, and the image content changes while the URL stays the same, imgrender still uses the cached image.
To avoid that, add or change a query parameter on the URL, as shown below.
Old URL:
```bash
https://www.imgrender.com/images/example.png
```
New URL:
```bash
https://www.imgrender.com/images/example.png?v=1
```
# Overview (/docs/template-guide/overview)
How it works [#how-it-works]
imgrender uses **declarative image generation**: you describe the template with familiar HTML and CSS, publish it, and pass variables through the API. imgrender renders that into a high-quality image.
```html
Hello imgrender
```
The code above generates a 400×200 pixel image with a gradient background and centered white text.
Template editor [#template-editor]
The [template editor](/playground "Open the template editor") is imgrender's online editing environment. It is useful for checking a template quickly before you write documentation or call the API.
In the template editor you can:
* Edit HTML and preview the render in real time
* Configure output parameters such as image size and format
* Manage and preview the fonts in use
* Start from a built-in template and quickly adapt it to your own style
* Parameterize the template with variables so one template can generate different images
* Open the API debug panel in one click and build a callable render request from the saved template
* Share the current editing state with a URL so others can collaborate or reproduce it
When building a template, finish the layout and styling in the [template editor](/playground "Open the template editor") first. After the result looks right, connect the [Generate image from template API](/docs/api/generate-image-by-template "Generate image from template API").
Core concepts [#core-concepts]
Image generation in imgrender works like this:
1. **Structure** - Use HTML to define the element hierarchy
2. **Styling** - Control appearance with CSS properties or Tailwind CSS
3. **Variable substitution** - Parameterize content with `{$ name $}` placeholders, which are replaced with real values at render time
4. **Rendered output** - imgrender renders the template and exports an image in the requested format
Compared with traditional image generation [#compared-with-traditional-image-generation]
| Approach | Advantages | Disadvantages |
| ------------------ | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| imgrender | Code is the image: easy to maintain, simple to call, version control, and dynamic generation | Requires learning |
| Design-tool export | WYSIWYG, no coding required | Hard to generate in bulk and hard to change |
| Canvas API | Highly flexible | Complex code, costly to maintain, and depends on a JS runtime |
HTML and CSS support [#html-and-css-support]
imgrender's rendering engine **does not fully follow browser standards**. It supports a subset of HTML and CSS.
imgrender does not guarantee that a render matches the browser exactly. Test it in the [template editor](/playground "Open the template editor").
HTML element limits [#html-element-limits]
imgrender accepts only static HTML fragments and does not run JavaScript. For dynamic content, use template variables, conditions, and loops.
Only a limited set of static, visible elements is supported:
* ✅ Supported: basic elements such as `div`, `span`, `p`, and `img`
* ❌ Not supported: ``, `