当前位置:网站首页>Do an online GIF synthesis service at no cost
Do an online GIF synthesis service at no cost
2022-06-26 22:07:00 【Hua Weiyun】
Because writing articles, I often need to do some GIF. But all kinds of online GIF The service was not very good ,
So I wonder if I can make one myself . So I did such a service .
So let me talk about , I know what I did today ?
One Business needs .
First, the first step is to realize the synthesis GIF This function .
Then we need to upload multiple files .
And then GIF Synthesis .
Finally save to local . Then return to the front end with a download link .
Finally, the service is deployed to the ECS .
Two technical requirement .
Python (3.6),Flask,Image
Python The installation of , Use the following statement to install the third-party package , Or directly pycharm Install in , In short, just install it
pip install flask
pip install Image
3、 ... and Technical realization
Take a look at the project structure
Look at the code first and then analyze
import osimport uuid from PIL import Imagefrom flask import Flask, render_template, request, send_from_directory frame = 10sleepTime = 1.0 / frameapp = Flask(__name__)BASE_PATH = os.path.dirname(os.path.abspath(__file__)) +"/download"def makeGif(imgList,uid): im = imgList[0] file_name = BASE_PATH +"/"+uid +".gif" im.save(file_name, save_all=True, append_images=imgList[1:], loop=0, duration=sleepTime) @app.route('/')def hello_world(): return render_template('upload.html') @app.route('/gif',methods=['POST'])def save_file(): uploaded_files = request.files.getlist("photo") uid = str(uuid.uuid4()) imgList = [] for file in uploaded_files: # Change here to store multiple files img = Image.open(file) imgList.append(img) makeGif(imgList,uid) download_url = "/download/"+uid+".gif" return render_template("download.html",download_url = download_url) @app.route("/download/<filename>", methods=["GET"])def download_file(filename): return send_from_directory(BASE_PATH, filename, as_attachment=True) if __name__ == '__main__': app.run()
Technical point :
1.uid Use
As a website , It may be used by many people at the same time, so I use it here uid As a unique identity .
2.Image Use
Image It is mainly used to synthesize GIF The main function of , Change the time of the picture duration Is to control the display time of each picture , You can set it yourself .
3.Flask Use
I haven't used it before flask. So some rendering of web pages is not very clear , But it's also very simple . As a placeholder, then pass the parameters .
Full code download address : Make your own online gif Composite services ,soeasy-Python Document resources -CSDN download
Four 、 Service deployment
First step Choose any service provider and buy a cloud server
The second step , Deployment environment install Python, establish Python Environmental Science , This step is also a routine operation , According to your own operating system installation environment .
Install third party package , Use the same command as above .
The third step , Start the server Use the following command
python main.py &
Put the service in the background , Otherwise, if you turn off the console, the service will be turned off .
Step four Start visiting Input to the browser http://ip:port/,ip It's the public network ip,port It's the external port you just opened
Replace your local ip And port , The following screen will appear , After selecting files , Click Create GIF.
Be careful : To choose more pictures , otherwise gif How to move
Click to return to the interface , There will be a download link . Just click download , You will get the following picture
5、 ... and 、 Points that can be optimized
1、 Abnormal inspection
Like synthesis , Save exception , Add exception handling to make the program more robust .
2、 Regular file cleaning
Currently synthesized gif It was not cleaned up , Will always be stored on the server , So do a scheduled task of automatic cleaning , Prevent the hard disk from bursting .
3、 Yes HTML Optimize your page .
Now the interface is so ugly , You can beautify the interface , Make users look more comfortable , There's nothing I can do about this
4、 Change how you deploy
Now it's used flask The default server . It is not recommended to use . Instability will occur when the flow is high . It can be replaced by the deployment scheme in production mode , But now it's enough to play by yourself , After all, it is not to serve all mankind .
5、 Some parameters of synthesis can be opened
Now the synthesis is to write dead parameters , The parameters can be opened and controlled by the user , For example, the changing time of each picture , The generated picture cycle effect and so on , It's more flexible .
6、 Image formatting
Now the size of the picture is not formatted , Later, you can unify the size of the picture according to your needs , Then synthesize .
6、 ... and , summary
This time is mainly to do a GIF The function of .
Used Python Of image library .
Then you have to use flask Of web function .
It's simple , They are the assembly of basic functions .
All in all : You can better .
边栏推荐
- Kdd2022 𞓜 unified session recommendation system based on knowledge enhancement prompt learning
- Unity 设置Material、Shader的方法
- 模块五作业
- 简述unity的模型动画功能
- Restfultoolkitx of idea utility plug-in -- restful interface debugging
- Leetcode (763) -- dividing letter ranges
- Parsing complex JSON in fluent
- Module externe unity3d anyportrait 2D Skeleton Animation
- 【题解】剑指 Offer 15. 二进制中1的个数(C语言)
- 简析攻防演练中蓝队的自查内容
猜你喜欢
网络爬虫2:抓取网易云音乐评论用户ID及主页地址
Web crawler 2: crawl the user ID and home page address of Netease cloud music reviews
模块五作业
[mathematical modeling] spanning tree based on Matlab GUI random nodes [including Matlab source code 1919]
Configuring assimp Library in QT environment (MinGW compiler)
亿级月活全民K歌Feed业务在腾讯云MongoDB中的应用及优化实践
AI intelligent matting tool - hair can be seen
leetcode:710. 黑名单中的随机数【映射思维】
【图像处理基础】基于matlab GUI图像曲线调整系统【含Matlab源码 1923期】
Restfultoolkitx of idea utility plug-in -- restful interface debugging
随机推荐
About appium trample pit: encountered internal error running command: error: cannot verify the signature of (solved)
Convolutional neural network (CNN) explanation and tensorflow2 code implementation
How to enable Hana cloud service on SAP BTP platform
leetcode:6107. 不同骰子序列的数目【dp六个状态 + dfs记忆化】
模块五作业
Unity 设置Material、Shader的方法
Unity布料系統_Cloth組件(包含動態調用相關)
网络爬虫2:抓取网易云音乐评论用户ID及主页地址
同花顺注册开户有没有什么风险?安全吗?
vulnhub之DC9
用C#通过sql语句操作Sqlserver数据库教程
VB. Net class library (advanced version - 1)
Is this a bug? Whether the randomly filled letters can be closed
Implementation of collaborative filtering evolution version neuralcf and tensorflow2
【混合编程jni 】第九篇之Jni总结
What is the “ How to remove a custom form list?
Configuring assimp Library in QT environment (MinGW compiler)
Yolov6: un cadre de détection de cibles rapide et précis est Open Source
Introduction to dependency injection in SAP Spartacus
WordPress collection plug-ins are recommended to be free collection plug-ins