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()