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: