GIF to ASCII Converter
Building on from our last project where we converted a simple image into ASCII art, we now are going to do the same with an entire GIF! The good news is that all of the hard work is already done. Since a GIF is just a series of still images played in a sequence, all we need to do is somehow extract every frame of our gif, do the same conversion to ASCII as we did in the last post, then put them all back together in the GIF format. Let's go over the changes, but before I bore you with the code, let's look at the results!


Pretty cool huh?
Next we convert each frame to ASCII text. I talked extensively about that process in my last post and it has not changed, so if you want to read more about that, check out this post.
The next step is where I have slightly changed methods from the last post. In the last post, I would leave a space between all the characters in my ASCII image in order to preserve the aspect ratio. Since each character is twice as tall as it is wide, if I did not do this, then the final image would look squished. I really didn't like how this looked though because it left a lot of whitespace in the image that took away from the final product. Instead of doing this, I now calculate the dimensions of the characters in the font that I am using, then use that to calculate and use the ratio between the height and the width of the font to adust the apect ratio of the original gif. I also use this data to calculate how many pixels my canvas, where I will draw the characters, needs to be. This all ensures that the final gif comes out looking correct.
Now that our Frames are created and stored in an array, the only step left is to convert them to GIF format. To do this, I use the Pillow module to create a temporary blank canvas and draw the text to it. This is so I can them measure the size of the text box, and create a final canvas that perfectly fits around it. I then create said canvas, draw the text to it, then save the image to an array. I then repeat this process for every frame in my new gif. Finally I save all the frames into gif format and we're done!
Here are some examples of some cool gifs I have made with this project: