首页 > 开发 > Python > 正文

python3 webp转gif格式的实现示例

2020-07-28 13:48:54
字体:
来源:转载
供稿:网友

使用PIL库,python3安装需要使用

pip install pillow
from PIL import Imageimport osimport reimgPath = './img/'webpReg = r'webp$'def getAllFile (filePath): files = os.listdir(filePath) return filesdef 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()

图片文件放在img目录下

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持错新网之家。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表