Predictive Hacks

Hack: How to create GIF Images in Python

gif

We will show how you can create GIF images in Python from a set of images. We will work with the imageio library and where we can install it as follows:

  • If you are in a conda env: conda install -c conda-forge imageio
  • If you have pip: pip install imageio

For this example, I used three images of Zach LaVine from a Slam Dunk contest.

The three images:

Let’s start:

import imageio
import os
files = os.listdir('my_images')

# assume that your images that you 
# want to make the GIF are under the my_images folder
images_path = [os.path.join('my_images',file) for file in files]

# fps are the frames per second
images = []
for img in images_path:
    images.append(imageio.imread(img))
imageio.mimsave('output/mygif.gif', images, fps=2)
 

voilà the GIF:

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Leave a Comment

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Python

Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.

Python

Intro to Chatbots with HuggingFace

In this tutorial, we will show you how to use the Transformers library from HuggingFace to build chatbot pipelines. Let’s