How to Create a Video from Images using PHP?

Creating short videos that can be shared on social media can be an effective way to share a collection of images. It is commonly used to display real estate listings, e-commerce products, and news videos, in which multiple photos are combined to make visually appealing slideshows. In order to convert images into video content using PHP, you'll need a video API. Here is how:

Input Code
// composer require creatomate/creatomate
$client = new Creatomate\Client('Your API Key');

$output = $client->render([
 // The ID of the template that you created in the online editor.
 'template_id' => '2e8bccbf-e40a-41d5-a815-f58518ed9835',

 // Inserting several images into the video template.
 'modifications' => [
  'Image-1' => 'https://cdn.creatomate.com/demo/living-room.jpg',
  'Image-2' => 'https://cdn.creatomate.com/demo/bathroom.jpg',
  'Image-3' => 'https://cdn.creatomate.com/demo/kitchen.jpg'
 ])
]);

var_dump($output);
Output Video

How it works: To get started, install the Creatomate library from Packagist using Composer. This package makes it easy to use Creatomate in your PHP code. Creatomate is a managed video API for programmatically creating MP4 videos using a simple REST interface. Because of its cloud-based architecture, you do not have to worry about maintaining your own server infrastructure.

In the example above, we are creating a simple video using a collection of images. The easiest way to do this is with a video template. In this case, we're using one of the pre-made real estate templates provided in the library. However, if you want to make your own video templates, you can use the online editor to make one that perfectly meets your needs.

Once you've created a template, you can use the API to generate the video. As you can see, this is just a matter of calling the "render" function and providing a list of "modifications". Here is where we list the images we want to insert into the video template. To keep it simple, we're only changing Image-1, Image-2, and Image-3, but you can change any aspect of the video, like text captions, video footage, logos, or colors. This will give you complete control over how the video is rendered, right from your PHP code.

After the "render" function returns, you'll get the MP4 back for further processing. You could, for example, post the video to social media or host it on your own site.

To get started, follow this quick tutorial or check out the API documentation.

Edit this Code Example in the Video Editor

Easily design your own video templates using the online editor. Then, export your templates as JSON and integrate them into your PHP application to create any kind of video – completely through code.

Related PHP Video Editing Questions

Start automating today

Start with a full-featured trial with 50 credits, no credit card required.
Get started for free