Create gif from images with python

Posted by: carl dsouza | in python | 1 year, 2 months ago | 0 comments

Here's a quick python snippet to create a gif from a set of pics.

There are a couple of ways to do this, but I'm using 'imageio'. This is available with both pip and conda, so either of the following works:

pip install imageio
conda install imageio

To use this, put the pictures you want to use to create the gif into a 'pics' folder

Some Details of working with gifs with imageio:

>>> import imageio
GIF-PIL - Static and animated gif (Pillow)

A format for reading and writing static and animated GIF, based
on Pillow.

Images read with this format are always RGBA. Currently,
the alpha channel is ignored when saving RGB images with this

Parameters for reading

Parameters for saving
loop : int
The number of iterations. Default 0 (meaning loop indefinitely).
duration : {float, list}
The duration (in seconds) of each frame. Either specify one value
that is used for all frames, or one value for each frame.
Note that in the GIF format the duration/delay is expressed in
hundredths of a second, which limits the precision of the duration.
fps : float
The number of frames per second. If duration is not given, the
duration for each frame is set to 1/fps. Default 10.
palettesize : int
The number of colors to quantize the image to. Is rounded to
the nearest power of two. Default 256.
subrectangles : bool
If True, will try and optimize the GIF by storing only the
rectangular parts of each frame that change with respect to the
previous. Default False.

For eg, I've been taking screenshots of google's weather froggie every once in a while (something to entertain the kids). I decided to put snapshots of the same scenery into a gif.

After running the code, it looks like this:

  Weather Froggie - Hilltop

Weather Froggie - House  Weather Froggie - Orchard 

 Weather Froggie - Picnic  Weather Froggie - Plains

Weather Froggie - River  Weather Froggie - Rooftop

Current rating: 1


There are currently no comments

New Comment


required (not published)


Barcelona, Spain

Licencing: Creative Commons License This work is licensed under a Creative Commons Attribution 4.0 International License.