Create GIF

You can create an animated GIF image using the Image.save() function.

Official documentation link:
https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html

Example 1: animate from a list of images
https://replit.com/@dniemitalo/PIL-animation-loop#main.py

Example 2: use for loop to move a baseball in space
https://replit.com/@dniemitalo/PIL-gif-loop#main.py

Example 3: draw color changing moving square
https://replit.com/@dniemitalo/PIL-gif-loop-2#main.py

The basic idea:

Use the Image.save() function to save the first frame, then set the append_frames option equal to a list of additional image objects. You can also set the duration between frames and tell it to repeat.

The easier part is putting the images together after you have them all loaded or created. The more interesting part is deciding what should be different about each frame and then writing code to create the different frames. See the second and third examples above for a couple of ways to think about that.