If you want to show off multiple pictures in a video-style presentation, an image slideshow is the way to go. It's a popular choice for social media videos, whether it's showcasing real estate listings, displaying a series of photos, or putting together an image collage. By using PHP and a video editing API, you can easily convert your images into dynamic slideshows. Here's how to do that in your PHP app using just a few lines of code:
// Don't forget to install the required library using Composer:
// composer require creatomate/creatomate
$client = new Creatomate\Client('Your API Key');
$output = $client->render([
'source' => new Creatomate\Source([
'output_format' => 'mp4',
'width' => 1920,
'height' => 1080,
'elements' => [
[
'type' => 'image',
'source' => 'https://cdn.creatomate.com/demo/living-room.jpg',
'track' => 1,
'duration' => 5,
'clip' => true,
'animations' => [
[
'easing' => 'linear',
'type' => 'scale',
'scope' => 'element',
'start_scale' => '120%',
'fade' => false
]
]
],
[
'type' => 'image',
'source' => 'https://cdn.creatomate.com/demo/bathroom.jpg',
'track' => 1,
'duration' => 5,
'clip' => true,
'animations' => [
[
'time' => 'start',
'duration' => 1,
'easing' => 'cubic-in-out',
'transition' => true,
'type' => 'slide',
'fade' => false,
'direction' => '180°'
],
[
'easing' => 'linear',
'type' => 'scale',
'scope' => 'element',
'start_scale' => '120%',
'fade' => false
]
]
],
[
'type' => 'image',
'source' => 'https://cdn.creatomate.com/demo/kitchen.jpg',
'track' => 1,
'duration' => 5,
'clip' => true,
'animations' => [
[
'time' => 'start',
'duration' => 1,
'easing' => 'cubic-in-out',
'transition' => true,
'type' => 'slide',
'fade' => false,
'direction' => '180°'
],
[
'easing' => 'linear',
'type' => 'scale',
'scope' => 'element',
'start_scale' => '120%',
'fade' => false
]
]
],
[
'type' => 'image',
'source' => 'https://cdn.creatomate.com/demo/house.jpg',
'track' => 1,
'duration' => 5,
'clip' => true,
'animations' => [
[
'time' => 'start',
'duration' => 1,
'easing' => 'cubic-in-out',
'transition' => true,
'type' => 'slide',
'fade' => false,
'direction' => '180°'
],
[
'easing' => 'linear',
'type' => 'scale',
'scope' => 'element',
'start_scale' => '120%',
'fade' => false
]
]
]
]
])
]);
var_dump($output);
How it works: In the above example code, we generate a dynamic slideshow using only PHP code. As a first step, install the Creatomate package from Packagist. The PHP library allows you to generate any type of video through a component-based architecture. Here we are composing a video scene using multiple photographs. We use a slide effect to smoothly transition each photo from one to the next.
By setting the "duration" property, each photo remains visible for 5 seconds, just enough time to highlight each one. You can enhance the visual appeal of the slideshow by giving each image a zoom effect, commonly known as the Ken Burns effect, through the "animations" property. With different options for each animation, you can create completely different slideshow effects.
To display the images in a sequence, simply place them all on track number "1". For example, if you'd like to include a logo as well, you can use a separate track number for that. This allows a lot of versatility when generating dynamic slideshows. For more advanced editing options, try out the online code video editor below. It enables you to design your own slideshow videos and export them as JSON for use in your PHP application.