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
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 :
Recommended in previous periods ——
project 1.0 Fireworks roses ( Contains multiple source code )
project 1.1 Love guide ( Contains multiple source code )
project 1.0 Flying snow applet
project 3.2 Automatic wallpaper change
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
The sidebar is recommended
- Python from 0 to 1 (day 14) - Python conditional judgment 1
- Several very interesting modules in Python
- How IOS developers learn Python Programming 15 - object oriented programming 1
- Daily python, Chapter 20, exception handling
- Understand the basis of Python collaboration in a few minutes
- [centos7] how to install and use Python under Linux
- leetcode 1130. Minimum Cost Tree From Leaf Values(python)
- leetcode 1433. Check If a String Can Break Another String(python)
- Python Matplotlib drawing 3D graphics
- Talk about deep and shallow copying in Python
guess what you like
-
Python crawler series - network requests
-
Python thread 01 understanding thread
-
Analysis of earthquake distribution in the past 10 years with Python~
-
You need to master these before learning Python crawlers
-
After the old friend (R & D post) was laid off, I wanted to join the snack bar. I collected some data in Python. It's more or less a intention
-
Python uses redis
-
Python crawler - ETF fund acquisition
-
Detailed tutorial on Python operation Tencent object storage (COS)
-
[Python] comparison of list, tuple, array and bidirectional queue methods
-
Go Python 3 usage and pit Prevention Guide
Random recommended
- Python logging log error and exception exception callback method
- Learn Python quickly and take a shortcut~
- Python from 0 to 1 (day 15) - Python conditional judgment 2
- Python crawler actual combat, requests module, python to capture headlines and take beautiful pictures
- The whole activity collected 8 proxy IP sites to pave the way for the python proxy pool, and the 15th of 120 crawlers
- Why can't list be used as dictionary key value in Python
- Python from 0 to 1 (day 16) - Python conditional judgment 3
- What is the python programming language?
- Python crawler reverse webpack, a real estate management platform login password parameter encryption logic
- Python crawler reverse, a college entrance examination volunteer filling platform encrypts the parameter signsafe and decrypts the returned results
- Python simulated Login, selenium module, python identification graphic verification code to realize automatic login
- Python -- datetime (timedelta class)
- Python's five strange skills will bring you a sense of enrichment in mastering efficient programming skills
- [Python] comparison of dictionary dict, defaultdict and orderdict
- Test driven development using Django
- Face recognition practice: face recognition using Python opencv and deep learning
- leetcode 1610. Maximum Number of Visible Points(python)
- Python thread 03 thread synchronization
- Introduction and internal principles of Python's widely used concurrent processing Library Futures
- Python - progress bar artifact tqdm usage
- Python learning notes - the fifth bullet * class & object oriented
- Python learning notes - the fourth bullet IO operation
- Python crawler actual combat: crawl all the pictures in the answer
- Quick reference manual of common regular expressions, necessary for Python text processing
- [Python] the characteristics of dictionaries and collections and the hash table behind them
- Python crawler - fund information storage
- Python crawler actual combat, pyteseract module, python realizes the visualization of boos direct employment & hook post data
- Pit filling summary: Python memory leak troubleshooting tips
- Python code reading (Chapter 61): delaying function calls
- Through the for loop, compare the differences between Python and Ruby Programming ideas
- leetcode 1606. Find Servers That Handled Most Number of Requests(python)
- leetcode 1611. Minimum One Bit Operations to Make Integers Zero(python)
- 06python learning notes - reading external text data
- [Python] functions, higher-order functions, anonymous functions and function attributes
- Python Networkx practice social network visualization
- Data analysis starts from scratch, and pandas reads and writes CSV data
- Python review (format string)
- [pandas learning notes 01] powerful tool set for analyzing structured data
- leetcode 147. Insertion Sort List(python)
- apache2. 4 + windows deployment Django (multi site)