Add a Text to an Image or Photo via API

APITemplate.io offers API to quickly overlay and format text or caption on any images or photos. 

Table of Contents

1. Introduction

Adding dynamic text to any of the images is easy with our API. Once an image template is created, you can overlay a dynamic text on top of the template. With APITemplate.io you can create variations of images based on the template. 

We integrate with some of the popular no-code platforms such as Zapier, Integromat or n8n for you to easily generate images with our image generation API.

In this tutorial, we are going to create a new image template. Subsequently, we can either automate the image generation with low-code platforms or any programming languages such as Python or even generate images with cURL command.

Let’s get started!

Over hundreds of quality fonts in our font library and you can style the text by changing the text element’s properties.

2. Create a reusable template with APITemplate.io

Step 1: Register and login to https://app.apitemplate.io

Step 2: In the dashboard, navigate to Manage Templates on the left menu

Step 3: In the Manage Templates page, click on the New Template Button

Step 4: Select any of the template and press Create button

Step 5: In the template list under Manage Templates, click the Launch Image Editor of the newly created template to start editing

Step 6: Update the text or change the properties of other elements according to your requirements. In this example we change the Name property to "text_quote"

TIPS: you need to choose a more meaningful name for your visual elements, especially the dynamic ones, which will be used to identify the visual elements in the the JSON

Step 7: Click on the API Console tab and click on the Generate JSON Data for Common Properties if the Sample JSON is empty. Then, change or update the JSON data in sample JSON.

You can manipulate the "text" property of "text_quote", it will be rendered in the image.

Step 8: Click on Quick Preview to have a look at the image. You can also select "Download Live Preview PNG" and press "Live Preview" to download the live preview PNG image.

Step 9: Finally you can integrate your template with REST API, Zapier, Integromat, n8n or some other platforms to create variations of images.

APITemplate.io integrates with the following platforms for you to generate images

*Integration with other platforms can be achieved using the platform’s HTTP/HTTPS component.

3. Add Text to An Image using Zaiper, Integromat or other low-code platforms

Low-code automation platforms like Zapier, Integromat, N8n are software applications that require very little or no coding knowledge, you can quickly put together a workflow with these tools. The followings are a few articles that help you to generate images with APITemplate.io

4. Add Text to An Image via API using cURL

cURL is a command-line tool for developers to get or send data including files using URL syntax. It's my favorite tool to quickly test out an HTTP/HTTPS request. The following is a cURL command to send a request for image creation.

				
					curl --header "Content-Type: application/json" \
-iL \
-H 'X-API-KEY: 6fa6g2pdXGIyxHRhVlGh7U5Vhdckt' \
  --data '"overrides": [ { "name": "text_quote", "text": "\"Happiness is not an ideal of reason, but of imagination.\"", "textBackgroundColor": "rgba(217, 217, 217, 0.33)", "color": "#0DFC9C" }, { "name": "text_author", "text": "Immanuel Kant" } ] }' \
  "https://api.apitemplate.io/v1/create?template_id=79667b2b1876e347"
				
			

5. Add Text to An Image via API using Python

Once an image template is created, you can make an API call to override the text in the image template to create new images. The following is an example to replace the text "text_quote" with a new quote:

				
					import requests, json

def main():
    api_key = "6fa6g2pdXGIyxHRhVlGh7U5Vhdckt"
    template_id = "79667b2b1876e347"

    data = {
    "overrides": [
            {
                "name": "text_quote",
                "text": "\"Happiness is not an ideal of reason, but of imagination.\"",
                "textBackgroundColor": "rgba(217, 217, 217, 0.33)",
                "color": "#0DFC9C"
            },
            {
                "name": "text_author",
                "text": "Immanuel Kant"
            }
        ]
    }

    response = requests.post(
        F"https://api.apitemplate.io/v1/create?template_id={template_id}",
        headers = {"X-API-KEY": F"{api_key}"},
        json= data
    )

if __name__ == "__main__":
    main()

				
			

The JSON response as follows:

				
					{
   "download_url":"https://bucket.s3.amazonaws.com/5641212-6e75.jpeg",
   "download_url_png":"https://bucket.s3.amazonaws.com/56423251-6e75.png",
   "template_id":"cd23222b188c5c42",
   "transaction_ref":"56413f91-6e75-47a1-93af-344b2f23552e2",
   "status":"success"
}
				
			

6. Conclusion

Besides Python, we also provide sample code for C#. Programming languages that have a library to make an HTTP/HTTPS request call can also integrate with our REST API easily.

In addition, we integrate with popular lowcode platforms such as Zapier, Integromat. They allow you to automate image generation without code.

Happy automating!