GIF Creator Using Python

A GIF as we all know is a series of images that is used to create an impression of movement. As youngsters memes have become and integral part of our life. Memes, GIFs are in daily usage to convey our emotions to our friends. Have you imagined how much fun it would be if you could create your personalized GIF to share it with your friends? Or maybe some people could use it as a part of their content creation game!

Let’s see how we can create GIFs. I will make use of Google Colab for this particular tutorial. You can make use of any editor of your choice

Firstly, we will add images of our choice to our notebook. I have added two images, “image1.png” and “image2.jpg”

Once you have added image of your choice we will import imageio module to create the GIF

import imageio

After this, we will add all the files into an array and use an for loop to append all the images in the sequence at which they are as an array element. The appended images will be stored in an new array called “images”

filenames = ["/content/image1.png","/content/image2.jpg"]
images = []
for filename in filenames:
    images.append(imageio.imread(filename))

Note:  indentation is an important part for python programming

Once we have all our images appended, we will make use of inbuilt method mimsave to save the images in GIF format

This method takes the first parameter as the name of GIF we want as our output. The second parameter will be the images array we have created. The third parameter is the type in our case it will be ‘GIF’ and the last parameter will be the duration in seconds

imageio.mimsave('movie.gif', images,'GIF',duration=1)

When you run this, you will have a GIF with name movie saved. Below is the GIF I created

You guys can be as creative as you wish to be with such amazing libraries provided by python
Happy coding!!

 

 

 

 

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories