Creating Animated GIFs, programatically!

I’m using Ubuntu 16.04 to play.

Week 1: Making GIFs

It’s not my first attempt at creating moving images. Each time I met with a problem that stopped me in my tracks until I ran out of steam and lost interest. But now two changes brought me success!
First I found out that Pillow 3.4.0 can now save images sequences!

Second I discovered Gizeh, a very nice library written by Zulko. Gizeh is a wrapper for cairocffi, which is a Python binding for Cairo, which is a 2D graphics library written in C… Lots of things to learn!

I did get into some trouble while installing Gizeh. Pip installed a version that was different from what is available on github. I didn’t have access to some elements (ellipse, bezier_curve, more?). To fix this I just replaced the file on my computer with the one from github.

To help with the gif making process I made an image viewer using Pillow and Tkinter. Mixing those two also gave me trouble. For some reason ImageTk was missing and I had to install python-pil.imagetk (thanks to saulspatz). After I managed to get the viewer running it was trivial to make a GIF from my pictures. By the way, do you know about Lena Söderberg?

Once I learened to make GIFs the next step was to learn how to draw my own images. Being lazy I used Gizeh’s square example as a starting point. The idea was to have those squares revolve.

I learned a lot with this little project. Not only about code but also about animation. (Getting a gif to loop perfectly can be tricky)

ps. Don’t forget to read about beautiful Lena

Here’s the code:

Leave a Reply

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