A basic walkthrough on how to split an animated gif into frames, inject text onto some of those frames, then rebuild into a GIF, all using Python's
The code basically works like this:
- Use PIL to break the gif into images.
- However, for compression purposes, some GIF frames have transparency, and rely on whatever the previous frame left behind.
- So, start with a blank canvas and continue pasting each frame on top and saving each individual result. This should net you various full-color frames.
- Write text onto the desired frames using math, etc. It's very primitive, I generate an "outline" by just pasting offset text four times in black, then once centered in white :)
- Rebuild a gif using the incredible FFMPEG.