Replace Image In Template
In this guide, you'll learn how to replace images within a template video. You can view the example template video here.
Retrieve Template Variables
You can fetch the template variables using the following API call:
curl -X GET 'https://api.heygen.com/v1/template.get?video_id=<video_id>' \
-H 'X-Api-Key: <your-api-key>'
{
"code": 100,
"data": {
"scenes": [
{
"variables": [
{
"name": "image_0",
"properties": [
{
"default": "<url>",
"name": "link"
},
{
"default": "cover",
"name": "fit"
}
],
"type": "image"
}
]
},
{
"variables": [
{
"name": "image_1",
"properties": [
{
"default": "<url>",
"name": "link"
},
{
"default": "cover",
"name": "fit"
}
],
"type": "image"
}
]
},
{
"variables": [
{
"name": "image_2",
"properties": [
{
"default": "<url>",
"name": "link"
},
{
"default": "cover",
"name": "fit"
}
],
"type": "image"
}
]
}
],
"template_id": "3662c26bfaf74c9189d2b0e260e8c727",
"video_id": "3662c26bfaf74c9189d2b0e260e8c727"
},
"message": "Success"
}
Customize Template Variables and Generate Video
Now, you can proceed to replace the images' link
variables in your template. Use the following API request:
curl --request POST \
--url https://api.heygen.com/v1/template.generate \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <your-api-key>' \
--data '
{
"template_id": "3662c26bfaf74c9189d2b0e260e8c727",
"title": "sub_image",
"variables": [
{
"properties": {
"link": "https://resource.heygen.com/image/cfdb164586d240999ce580d8649ec792/1920x1080.jpeg",
"fit": "cover"
},
"name": "image_0"
},
{
"properties": {
"link": "https://resource.heygen.com/image/cfdb164586d240999ce580d8649ec792/1920x1080.jpeg",
"fit": "contain"
},
"name": "image_1"
},
{
"properties": {
"link": "https://resource.heygen.com/image/cfdb164586d240999ce580d8649ec792/1920x1080.jpeg",
"fit": "crop"
},
"name": "image_2"
}
],
"test": false
}'
View the Result
Let's take a look at how a template video can be transformed. Below, you'll find the original template video and the video after customizing it.
Here's the original template video:
And here's the video after customizing it, where we've replaced the images within the template:
As you can see, with HeyGen's API, you can seamlessly replace image content within templates, offering endless possibilities for customization and personalization.
Updated 4 months ago