11行python代码实现把webp转jpg格式图片(同路径下)

from os import *
from PIL import Image

PATH = r"C:\Users\Administrator\Desktop"
for root, dirs, files in walk(PATH):
    for f in files:
        if path.splitext(f)[1] == ".webp":
            img = Image.open(f)
            img.load()
            img.save(f[0:-5] + ".jpg")
            remove(f)

这应该是最简洁的了,不过此代码需要在PATH路径下运行,也就是要跟图片的路径一样才行

python
161 views
Comments
登录后评论
Sign In
·

代码可以高亮:

from os import *
from PIL import Image

PATH = r"C:\Users\Administrator\Desktop"
for root, dirs, files in walk(PATH):
    for f in files:
        if path.splitext(f)[1] == ".webp":
            img = Image.open(f)
            img.load()
            img.save(f[0:-5] + ".jpg")
            remove(f)

下面的选择框选择 python 就可以

·

加油(ง •̀_•́)ง

·

66666666666