How to Turn Images Into Slideshow Videos using Python?

If you're looking to showcase multiple pictures in a video-style presentation, an image slideshow is an excellent way to do that. It's widely used in social media videos, whether to feature real estate listings, display a series of photos, or create an image collage. By utilizing Python and a video editing API, you can easily convert your images into dynamic slideshows. The following Python example shows how to implement this completely using code:

Input Code
import requests

json = {
 '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': 4,
    '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
     }
    ]
   }
  ]
 }
}

response = requests.post(
 'https://api.creatomate.com/v1/renders',
 headers={
  # Find your API key under 'Project Settings' in your account:
  # https://creatomate.com/docs/api/rest-api/authentication
  'Authorization': 'Bearer Your-API-Key',
  'Content-Type': 'application/json',
 },
 json=json
)

# Wait a minute, then visit the URL provided in the response:
print(response.json())

Output Video

How it works: There is no need to install any software, as all that is required is the "requests" package that comes standard with every Python installation. In the above code example, we generate an interactive slideshow entirely through Python code. This approach uses a JSON-based format to compose a video scene where multiple photos are displayed for a few seconds each. These images smoothly transition from one to another using a simple transition effect.

By setting the "duration" property, each photo remains visible for precisely 5 seconds. With the "animations" property, we can apply zoom effects to individual images to enhance the visual appeal of the slideshow. There are a range of options available for each animation, so you can create slideshow effects suitable for the style of your presentation.

To display the images in a specific sequence, we simply assign them all to track number "1". If we want to add a logo or text captions, we can assign those elements to separate track numbers and have them overlay the slideshow. This gives you a lot of flexibility to make any kind of dynamic slideshow within your Python application.

If you would like to create more advanced video slideshows, we recommend using the video editor below. With this online tool, you can make your own video scenes and export them as Python code.

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 Python application to create any kind of video – completely through code.

Related Python Video Editing Questions

Start automating today

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