Fundamentals 3 min read

Reversing a GIF Using Python Pillow (PIL)

This tutorial explains how to reverse an animated GIF by loading it with Pillow, extracting each frame, reversing the frame order, and saving the result as a new GIF, providing complete Python code and step‑by‑step instructions.

IT Services Circle
IT Services Circle
IT Services Circle
Reversing a GIF Using Python Pillow (PIL)

This tutorial explains how to reverse an animated GIF by loading it with Pillow, extracting each frame, reversing the frame order, and saving the result as a new GIF.

Import the required library:

from PIL import Image, ImageSequence

Load the GIF and split it into frames:

# Load local GIF
image = Image.open("cg.gif")
# GIF frame iterator
list = ImageSequence.Iterator(image)

Save each frame to a folder and collect them:

imgs = []
k = 1
for frame in list:
    frame.save("./chenge/img_%d.png" % k)
    imgs.append(frame.copy())
    k += 1

Reverse the frame list and save the new reversed GIF:

imgs.reverse()
imgs[0].save("reverse_cg.gif", save_all=True, append_images=imgs[1:])

The article also provides the complete source code combining all the steps above.

Pythonimage-processingGIFpillowreverse-animation
IT Services Circle
Written by

IT Services Circle

Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.