python脚本webp

不要随便用网上的脚本,SB太多了,害我丢了图片

https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.0.0-windows-x86.zip

注意\b转义符

import os
import os.path
import sys

encoder_path = """D:\paper\libwebp-1.0.0-windows-x64\\bin\cwebp.exe"""

if os.path.exists("result") :
    print("The result director exists.")
    sys.exit()

os.mkdir("result")
for path in os.listdir('.'):
    if not os.path.isfile(path): continue
    if not os.path.splitext(path)[1] in ['.png','.bmp'] : continue
    #commond = encoder_path + " -lossless " + path + " -o result"+ os.sep + path + ".webp"
    commond = encoder_path + " -lossless " + path + " -o result"+ os.sep + os.path.splitext(path)[0] + ".webp"
    os.system(commond)

猜你喜欢

转载自blog.csdn.net/haseetxwd/article/details/80654841