Python implements GIF graph upside down

Preface

GIF pictures have now been integrated into our daily online life, WeChat groups, QQ groups, circle of friends...if you don’t agree, you will fight pictures. Are you afraid? Don't worry, as long as you learn Python's GIF reverse playback skills, you are the "King of Doutu".

Let's start directly with the content of this article!

PIL(Python Image Library)

It is a third-party image processing library of python, with very powerful functions, and is almost recognized as the official image processing library of Python.

1 : Import the module of the PIL library

from PIL import Image, ImageSequence #Import the Image and ImageSequence modules of the PIL library
im = Image.open(r'./1.gif') #Note that the gif animation is placed in the same directory of the program

2 : Decompose the GIF image

In order to understand the principle of this program more intuitively, we can save all the pictures of the program's decomposition gif animation.

sequence =[] #Used to store the sequence of GIF decomposed into frames
i=0for f in ImageSequence.Iterator(im): #Cycle through frame by frame in GIF
 sequence.append(f.copy()) 
 i+=1  
 f.save('out_'+str(i)+'.png')  #Save each separated frame

3 : Reverse the sequence obtained by the reverse() function

sequence.reverse()

4 : Restore the obtained frame sequence back to GIF:

sequence[0].save(r'./out_zr640.gif',save_all = True, append_images=sequence[1:]) #The reversed gif is saved in the current directory

Show results:

The above is the detailed content of Python to realize GIF reverse playback. For more information about Python GIF reverse playback, please pay attention to other related articles on ZaLou.Cn!

Recommended Posts

Python implements GIF graph upside down
Python implements Super Mario
Python implements tic-tac-toe game
Python implements tic-tac-toe game
Python implements man-machine gobang
Python implements Tetris game
Python implements image stitching
Python implements minesweeper game
Python implements scanning tools
Python implements threshold regression
Python implements minesweeper games
Python implements electronic dictionary
Python implements guessing game
Python implements WeChat airplane game
Python implements word guessing game
Python implements a guessing game
Python drawing ring graph method
Python implements parking management system
Python implements digital bomb game
Python implements TCP file transfer
Python numpy implements rolling case
OpenCV Python implements puzzle games
Python implements password strength verification
Python implements car management system
Python implements code block folding
Python implements panoramic image stitching
Python implements SMTP mail sending
Python implements multi-dimensional array sorting
How Python implements FTP function
Python implements mean-shift clustering algorithm
Python implements gradient descent method
Python draw bar graph (bar graph) example
Python implements image stitching function
Python implements the brick-and-mortar game