Generate banners for Twitter with DynaPictures

How to Generate Banners for Tweets using DynaPictures

Published on:

Updated on:

Table of Contents

1. Overview

2. Prepare Image Template

3. Get API Key

4. Generate Image Variations

1. Overview

On this page, you will learn how to create an image template in DynaPictures, an image generation platform with API, and use REST API to generate image variations for this template. 

2. Prepare Image Template

In this section, we will create an image template containing a Twitter banner with a bubble, quote text and author’s info.

Sign in to DynaPictures, go to “Image Templates” on the left, and click on the “New Image Template” button.

Twitter banner templates library DynaPictures
Choose a banner template

New image template will be created and the template editor page will be opened. Now you can edit the template name, change size, and add new layers. All changes are automatically saved when you make them. See the annotations on the image below:

Customizable layers of Tweet banner post
Customize layers for the Tweet banner

We need to change the template size so that it’s square and has the correct resolution. Select the “Square (1200×1200)” option in the dropdown next to the template’s name.

Now let us add the following layers needed for the banner:

a) Background image

Click on the image icon in the toolbar. Resize the image element so that it fits the entire container. Click on the “Upload” button in the image element and upload an image that will be used as a background. 

Change the layer name to “background” in the layer settings panel on the right. It’s the “Layer Name” field at the bottom of the settings area. This name can be used later in REST API calls to customize the layer in generated images.

b) Quote Text

Click on the text icon in the toolbar and position the quote text area by dragging and resizing it. Select the background color in the settings panel and set the transparency (the A field in the RGBA row) level to 63. The padding must be set to 40, the border radius to 30, and the layer name to “quote_text”.

Customizing quote and background
Customize the text and background of the Tweet banner

c) Author Avatar

Click on the image icon in the toolbar and then resize and position the image element for the author avatar. Set the border color to #FFFFFF and the A field for transparency to 58. The border radius can be set to 102 or some other value, depending on the size of the image element, so that it becomes round. Set the layer name to the “avatar”.

Adding author avatar to Tweet banner
Adding author avatar

d) Author Name

Click on the text icon in the toolbar and then resize and position the text element next to the avatar. You can keep an auto-resizing option for the text size in the settings panel, or set the font size manually. Depending on the color of your background image, you may change the color of the text as well. Set the layer name to the “author”.

e) Author Username

Click on the text icon in the toolbar and resize and position the created text element next to the avatar and below the author’s name. Adjust the font size and the color if needed. Set the layer name to “username”.

The image template is ready now and you can go to “API Console” at the top and see the sample REST request made to the designs endpoint. This sample request contains test data for every layer in the template so that you can see what can be customized. In the next section, we will make such a REST request on our own.

3. Get API Key

Before you start using the DynaPictures REST API, you need an API key. The API key is a unique identifier that authenticates requests associated with your account for usage and billing purposes. To get an API key, click on your name in the upper right corner and go to the Account page. You will see an API Key section where you can copy your key.

How to get DynaPictures API key to generate Twitter banners
Get your DynaPictures API key

4. Generate Image Variations

Now we can start generating image variations via REST API. You can use your favourite programming language, command line, or tools like Postman or Insomnia. We will need an ID of the template that will be used to generate images. You can get it in the upper left corner of the template page:

Template ID from DynaPictures to generate banner posts for Twitter
Get the ID of the template to generate images

Here are the details of the request that we are going to make:

Endpoint URL https://api.dynapictures.com/designs/{template_id}
Request Method POST
Header “Authorization” Bearer {API_KEY}
Header “Content-Type” application/json
Request Body JSON Document with layer settings

We define the specific settings for the image template in the request body so that DynaPicture knows how to customize the template and generate an image variation. For example, here is a sample JSON document with customizations for the canvas background color, quote text, author name, and username. 

As you can see, we specify the name of the layer in the “name” attribute of the parameter object and then set other attributes like “text” for the text content of the text element or “imageUrl” for the image element. See API Reference for more details.

Finally, let us make a REST request and generate an image now. We will use the command line in this example. Please make sure you replace the MY_API_KEY and MY_TEMPLATE_ID with your actual values:

The following response document is returned synchronously, once the image is generated:

Congratulations! We generated our first image variation and can download it by opening the URL provided in the “imageUrl” field:

Example of the generated banner for. Twitter
Generated Tweet