current position:Home>[Python actual combat sharing] I wrote a GIF generation tool, which is really TM simple (Douluo continent, did you see it?)

[Python actual combat sharing] I wrote a GIF generation tool, which is really TM simple (Douluo continent, did you see it?)

2022-02-01 11:24:42 Muzixue Python

Introduction ​

 picture

well ! Hello everyone , I'm kimiko ! Today brings you a fun Python Applet , Hope you enjoy it , Remember to pay a little attention ~

Is there any content or form , Smaller than small video , Richer than ordinary pictures ????

** Yes !**

GIF Dynamic graph is one of them , and , essential .

GIF Dynamic graph should have been flooded with the Internet , It's a pleasure to be played by everyone , Everyone has long been unable to accept the pure text or static pictures in the article , These are long overdue

Now what you think . Only dynamic graphs , Only in this way can we express the great power in our body .

​ Ha ha ha , Today, Muzi takes Douluo as an example , Teach you to make several different character styles GIF Moving graph !

( In other words, everyone should have seen this Guoman , Crazy pursuit —— It's just that the update is a little slow ! Amway Amway , Although slow, there are also 100 More episodes , You can go to kangkanga ~)

​​ Text

​ ​ ​ ​ ​ ​ ​

He did it for her , You can give your life , Suicide bone removal . She did it for him , Can burn your life , Sacrificial Soul Ring .

                                                                                             —— Three little Tang family Doulo land

​ One 、 ordinary GIF Make

1) In preparation

1.1  The environment involved in simple dynamic drawing production is as follows :

Python3、Pycharm、Pillow modular .

Module installation :

pip install + Module name   or pip install -i https://pypi.douban.com/simple/ + Module name 
 Copy code 

1.2 Material preparation

The first group : Little dance 3 Pictures .

The second group : Ning Rongrong 8 Pictures .

2) Brief introduction

PIL The most important class is Image You can load images from files , Or process other images , Or from scratch establish .

To load an image from a file adopt Image Modular open() function .

3) Code demonstration

It is formed by the opening of continuous pictures gif chart .( The effect of dynamic video is put at the back )

'''
 Source base :#959755565#
csdn account number : Gu Muzi acridine 
 official account :Python Gu Muzi acridine 
'''
from PIL import Image

im = Image.open("1.jpg")
images = []
images.append(Image.open('2.jpg'))
images.append(Image.open('3.jpg'))
.......# As many as there are 
im.save('gif.gif', save_all=True, append_images=images, loop=1, duration=1, comment=b"aaabb")
 Copy code 

Two 、 upgrade imageio Of GIF Make

1) In preparation

1.1 The environment involved in simple dynamic drawing production is as follows :

Python3、Pycharm、imageio modular .

Module installation :

pip install + Module name   or pip install -i https://pypi.douban.com/simple/ + Module name 
 Copy code 

1.2 Material preparation

The first group : Little dance 30 Pictures .

The second group : Zhu Zhuqing, Dai mubai 37 Pictures .

2) Brief introduction

IMAIO It's a Python library , It provides a simple interface to read and write a large amount of image data , Including animated images 、 Volume data and scientific formats . It is

Cross platform , Running on the Python 2 .x and 3.x On , And easy to install .

 imageio.imread() # Read image from specified file . Return to one NUMPY Array , This array has meta properties of metadata .

Be careful , The image data is returned as is , And may not always have uTI8 Of dType( Therefore, it may be different from, for example PIL return ). 

3) Code demonstration

First read the static diagram to the list , As GIF Each frame ; Then set the input ( Static diagram )、 Output ( Dynamic graph ) And some necessary parameters , Here we set the interval between each frame to xx second , The default is 1 second , Then call miageio.mimsave Function to save the result .( The effect of dynamic video is put at the back )

'''
 Source base :#959755565#
csdn account number : Gu Muzi acridine 
 official account :Python Gu Muzi acridine 
'''
import imageio
def create_gif(image_list, gif_name, duration = 1.0):
    '''
    :param image_list:  This list is used to store the pictures that generate the motion graph 
    :param gif_name:  character string , Generated by gif file name , belt .gif suffix 
    :param duration:  Image interval 
    :return:
    ''' 
    frames = []
    for image_name in image_list:
        frames.append(imageio.imread(image_name))

    imageio.mimsave(gif_name, frames, 'GIF', duration=duration)
    return

def main():
    # Put the pictures you need to synthesize here 
    image_list = ['xx', 'xx', 'xx']  # You can put more than one 
    gif_name = 'new.gif'  # synthesis gif The drawing name can be modified 
    duration = xx  # The interval between each frame is xx second 
    create_gif(image_list, gif_name, duration)

if __name__ == '__main__':
    main()
 Copy code 

3、 ... and 、 Total effect display

​​

​ ​ ​ ​ ​ ​ ​

summary

Every trick deserves to be taken seriously ! I hope it helps you .

​​

Complete free source code collection office :

For complete project source code + See... For the source code base of the material :# Private letter editor 06# Or click the blue text to add to get free benefits !

Recommended in previous periods ——

project 1.0 Fireworks roses ( Contains multiple source code )

Python Confession code :“ Starlight, moon and night fireworks belong to you , I belong to you, too ”( Fireworks are in full bloom 、 Attached rose )

project 1.1 Love guide ( Contains multiple source code )

【Python Love guide 】 Two sweetness burst table applet comes out — I'm afraid I can't find an object ?

project 1.0 Flying snow applet

Python Applet : You see ? This is a snow scene that is hard to see in a thousand years —— It's just “ Beautiful to foul ”【 The screen is full of snowflakes 】

project 3.2 Automatic wallpaper change

【Python Advanced skills 】 It's cool , The computer automatically changes the wallpaper every day , This artifact suits you .

A summary of the article ——

project 1.0 Python—2021 | Summary of existing articles | Continuous updating , Just read this article directly

( More + The source code is summarized in the article !! Welcome to ~)

copyright notice
author[Muzixue Python],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/02/202202011124393627.html

Random recommended