本文章向大家介绍如何在python3项目中将webp转换成gif格式的基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
Python是一种编程语言,内置了许多有效的工具,Python几乎无所不能,该语言通俗易懂、容易入门、功能强大,在许多领域中都有广泛的应用,例如最热门的大数据分析,人工智能,Web开发等。
使用PIL库,python3安装需要使用
pip install pillow
from PIL import Image
import os
import re
imgPath = './img/'
webpReg = r'webp$'
def getAllFile (filePath):
files = os.listdir(filePath)
return files
def handleConversion (fileName):
fileName = imgPath + fileName
print('fileName--->', fileName)
saveName = fileName.replace('webp', 'gif')
print('saveName--->', saveName)
im = Image.open(fileName)
im.save(saveName, 'gif', save_all=True)
def main():
files = getAllFile('./img')
for fileName in files:
gifName = fileName.replace('.webp', '.gif')
# webp格式且未转过的才需要转
if re.findall(webpReg, fileName) != [] and (gifName not in files):
handleConversion(fileName)
if __name__ == '__main__':
main()
以上就是小编为大家带来的如何在python3项目中将webp转换成gif格式的全部内容了,希望大家多多支持亿速云!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。