"Emoticon" is an indispensable way of communication on the current social software, it is difficult to express the meaning of words, send an "emoticon", the other party will be able to understand. The following is a small faction of the production of an emoticon, accurately speaking, in the existing emoticon on the basis of the secondary processing and become.
The following is the simplest form of code (about 10 lines), introduces the above "emoticon" production process. First, the GIF animation will be split into graphic frames. The following figure is a GIF format motion picture found on the network.
To split the above GIF format motion picture into graphic frames using Python, just enter the following code. Line 1-2 is to import os library and Image function function from PIL library. Line 3 is to open the dynamic picture named "" located in the path of D disk. Line 4 is to create a folder named "Graphics Split", which is used to save the split graphic frames. Lines 5-12 use try-except exception handling and while loops to find and save graphic frames to the "Graphics Split" folder. Line 12 prints the total number of frames split. This Python split GIF animation code is only 13 lines, compared to other methods is very simple.
import os from PIL import Image im = ('D:\\Python\\gif\\') ('Graphic splitting') try: i = 0 while True: (i) ('Graphic splitting/'+str(i)+'.png') i = i +1 except: pass print('Total number of disassembled image frames'+str(i))
By running the above code, the dynamic graph named "" is split into 36 frames as follows.
Second, the split graphics for secondary processing. For example, to type their favorite "lines", here to "out of the waves" 4 words to the above split graphics, you can use Photoshop and other graphics processing tools. If you use Photoshop, because after the split graphics for the png format, directly open the "index" status will be displayed, this time you can through the "Image" - & gt; "mode "->" RGB color "will be png into layers, and then through" move "->" top alignment / right alignment "will be a multi-frame graphic layer stacked alignment, and then hit the" line "and saved one by one into a png, the following chart. Of course, do not use Photoshop, the use of other software to add text is fine. Here will be the secondary processing of graphics saved in the "graphics merge" folder, to facilitate the third step of the operation.
Third, Python will merge the graphic frames in the second step into a GIF motion picture. Input the following code: line 1 is to import imageio, os module, line 2 to create an empty file named images, used to save multi-frame graphics. Line 3 () lists the names of all the graphics in the "Graphics Merge" folder. Lines 4-5 read the listed graphic names in a for-in loop. Line 6() generates GIF format animated graphics, duration=0.1 means each frame is 0.1 seconds apart. This Python code for merging GIF motion graphics is even simpler, just 6 lines.
import imageio, os images = [] numberlist = ('Graphic merging') for i in range(len(numberlist)): (('Graphics Merge/'+numberlist[i])) ('',images,'GIF',duration=
Save and run the above code to get the Python emoticon "Come out to wave".
Of course, now there are a lot of "emoticon" software, do not need to be so complicated. But here is mainly to feel Python split GIF animated image into multiple graphic frames, as well as merge multiple graphic frames into GIF animated image process.
This is the whole content of this article.