python实现多文件夹下图片类型转换(png转webp)

import glob
import os
import threading

from PIL import Image

def create_image(infile, index):
os.path.splitext(infile)
im = Image.open(infile)
filePath = infile[0:infile.index("/")]
fileName = infile.lstrip(filePath + "/").rstrip(".png")
newFile = filePath + "/" + fileName + ".webp"
im.save(newFile, "WEBP")
print(newFile + ".webp" + "..........ok!........")

if os.path.exists(infile):
    os.remove(infile)
    print("........delete....." + infile + ".....ok")

def start():
filePathArr = ['drawable', 'drawable-hdpi', 'drawable-xhdpi']
for filePath in filePathArr:
index = 0
for infile in glob.glob(filePath + "/*.png"):
t = threading.Thread(target=create_image, args=(infile, index))
t.start()
t.join()
index += 1

if name == "main":
start()

from https://my.oschina.net/u/435726/blog/1623488

你可能感兴趣的:(python实现多文件夹下图片类型转换(png转webp))