imgrender

Blueprint - describe image content

Describe and control the content in an image

Migration notice

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. Design your template in HTML and define variables in 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

A blueprint fully describes the image dimensions and the content in the image. The properties are:

Field nameData typeDefaultRequiredDescription
widthintyesImage width. Content cannot exceed this width. Maximum 1100.
heightintyesImage height. Content cannot exceed this height. Maximum 2480.
backgroundColorHex Color CodeyesImage background color. Must be a hexadecimal color code.
borderColorHex Color Code#000000Color of the four borders.
borderWidthint0Width of the four borders. Half of the border width lies inside and half lies outside. This split cannot be adjusted yet.
borderRadiusint0Corner radius of the four border corners.
borderTopLeftRadiusint0Corner radius of the top-left border corner. Takes priority over borderRadius.
borderTopRightRadiusint0Corner radius of the top-right border corner. Takes priority over borderRadius.
borderBottomLeftRadiusint0Corner radius of the bottom-left border corner. Takes priority over borderRadius.
borderBottomRightRadiusint0Corner radius of the bottom-right border corner. Takes priority over borderRadius.
textsArray[]Text in the image. See Text.
imagesArray[]Images in the picture. An external image can be rendered onto the new image. See Image.
linesArray[]Lines in the image, useful as dividers. See Line.
qrcodesArray[]QR codes in the image. A QR code can be rendered on the image. See QR code.
blocksArray[]Rectangles in the image. See Rectangle.

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

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).

imgrender coordinate system diagram

Text

The text component adds text to an image.

The properties are:

Properties

Field nameData typeDefaultRequiredDescription
xintyesText X coordinate.
yintyesText Y coordinate.
textstringyesText content.
widthintyesText width. Sets the maximum display width. Text that exceeds this width wraps automatically.
fontstringSourceHanSansSC-NormalFont used to render the text. See Font.
fontSizeint18Font size, in pt.
lineHeightintBase font heightLine height. Cannot be smaller than fontSize.
lineSpacingfloat1Line-spacing multiplier. lineSpacing * fontSize = lineHeight.
colorArray#000000Text color.
textAlignstringleftHorizontal alignment. Allowed values: left, center, and right.
zIndexint0Stacking order. Affects how content in the same position covers other content.

Anchor

The textAlign property affects the text anchor.

imgrender text component

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

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.

hacker neo
Font nameName
jiangxizhuokaiJiangxi Zhuokai
slideyouranSlide Youran Xiaokai
SourceHanSansSC-HeavySource Han Sans SC Heavy
SourceHanSansSC-BoldSource Han Sans SC Bold
SourceHanSansSC-MediumSource Han Sans SC Medium
SourceHanSansSC-RegularSource Han Sans SC Regular
SourceHanSansSC-NormalSource Han Sans SC Normal
SourceHanSansSC-LightSource Han Sans SC Light
SourceHanSansSC-ExtraLightSource Han Sans SC ExtraLight
SourceHanSerifCN-HeavySource Han Serif CN Heavy
SourceHanSerifCN-BoldSource Han Serif CN Bold
SourceHanSerifCN-SemiBoldSource Han Serif CN SemiBold
SourceHanSerifCN-MediumSource Han Serif CN Medium
SourceHanSerifCN-RegularSource Han Serif CN Regular
SourceHanSerifCN-LightSource Han Serif CN Light
SourceHanSerifCN-ExtraLightSource Han Serif CN ExtraLight
Alibaba-PuHuiTi-HeavyAlibaba PuHuiTi Heavy
Alibaba-PuHuiTi-BoldAlibaba PuHuiTi Bold
Alibaba-PuHuiTi-MediumAlibaba PuHuiTi Medium
Alibaba-PuHuiTi-RegularAlibaba PuHuiTi Regular
Alibaba-PuHuiTi-LightAlibaba PuHuiTi Light

Example

{
  "x": 320,
  "y": 185,
  "text": "Davinci Li",
  "font": "SourceHanSansSC-Normal",
  "fontSize": 22,
  "color": "#fff",
  "width": 320,
  "textAlign": "center"
}

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

Field nameData typeDefaultRequiredDescription
xintyesImage X coordinate.
yintyesImage Y coordinate.
urlurlyesImage URL. The image must be accessible for download. Supported formats: gif, jpeg, png, bmp, tiff, and webp.
widthintyesRendered width, used to scale the image.
heightintyesRendered height, used to scale the image.
borderColorHex Color Code#000000Color of the four borders.
borderWidthint0Width of the four borders.
strokeAlignstringCENTERBorder alignment. Allowed values: CENTER (center), INSIDE (inside), and OUTSIDE (outside).
borderRadiusint0Corner radius of the four border corners.
borderTopLeftRadiusint0Corner radius of the top-left border corner. Takes priority over borderRadius.
borderTopRightRadiusint0Corner radius of the top-right border corner. Takes priority over borderRadius.
borderBottomLeftRadiusint0Corner radius of the bottom-left border corner. Takes priority over borderRadius.
borderBottomRightRadiusint0Corner radius of the bottom-right border corner. Takes priority over borderRadius.
zIndexint0Stacking order. Affects how content in the same position covers other content.
imgrender image component

Example

{
  "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

The line component adds a line to an image. Use it to draw dividers, underlines, and similar marks.

Properties

Field nameData typeDefaultRequiredDescription
startXintyesStart X coordinate.
startYintyesStart Y coordinate.
endXintyesEnd X coordinate.
endYintyesEnd Y coordinate.
widthintyesLine width.
colorHex Color Code#000000Line color.
zIndexint0Stacking order.

Example

{
  "startX": 30,
  "startY": 696,
  "endX": 610,
  "endY": 696,
  "width": 1,
  "color": "#E1E1E1",
  "zIndex": 1
}

Rectangle

The rectangle component adds a rectangle to an image.

Properties

Field nameData typeDefaultRequiredDescription
xintyesRectangle X coordinate.
yintyesRectangle Y coordinate.
widthintyesRectangle width.
heightintyesRectangle height.
backgroundColorHex Color Code#000000Background color.
borderColorHex Color Code#000000Color of the four borders.
borderWidthint0Width of the four borders.
strokeAlignstringCENTERBorder alignment. Allowed values: CENTER (center), INSIDE (inside), and OUTSIDE (outside).
borderRadiusint0Corner radius of the four border corners.
borderTopLeftRadiusint0Corner radius of the top-left border corner. Takes priority over borderRadius.
borderTopRightRadiusint0Corner radius of the top-right border corner. Takes priority over borderRadius.
borderBottomLeftRadiusint0Corner radius of the bottom-left border corner. Takes priority over borderRadius.
borderBottomRightRadiusint0Corner radius of the bottom-right border corner. Takes priority over borderRadius.
zIndexint0Stacking order. Affects how content in the same position covers other content.
imgrender rectangle component

Example

{
  "x": 220,
  "y": 100,
  "width": 380,
  "height": 200,
  "backgroundColor": "#fff",
  "borderColor": "#fff"
}

QR code

The QR code component adds a QR code to an image, for example a QR code for a share link.

Parameters

Field nameData typeDefaultRequiredDescription
xintyesQR code X coordinate.
yintyesQR code Y coordinate.
sizeintyesSize of the square QR code.
contentstringyesQR code content.
foregroundColorHex Color Code#000000QR code foreground color.
backgroundColorHex Color Code#ffffffQR code background color.
zIndexint0Stacking order. Affects how content in the same position covers other content.
imgrender QR code component

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

{
  "x": 208,
  "y": 726,
  "size": 200,
  "content": "http://weixin.qq.com/r/yRzk-JbEbMsTrdKf90nb",
  "foregroundColor": "#000",
  "backgroundColor": "#fff",
  "zIndex": 1
}

On this page