from os import *
from PIL import Image
PATH = r"C:\Users\Administrator\Desktop"
def convert(list):
for webp in list:
if path.splitext(webp)[1] != ".webp": continue
# 打开图片并赋值一份新的图片
wept = path.join(PATH, webp)
img = Image.open(wept)
img.load()
# 将赋值的图片修改后缀保存在原路径
img.save(path.join(PATH, webp[0:webp.rindex('.')] + ".jpg"))
# 删除原webp图
remove(wept)
list = []
for root, dirs, files in walk(PATH):
for f in files: list.append(f)
convert(list)
20行代码把桌面的webp转成jpg格式图片
PATH对应路径,可以是任意路径