windows下用python将webp批量转换为jpg

https://storage.googleapis.com/downloads.webmproject.org/releases/webp/index.html

还好谷歌提供了工具包

下载地址:工具包

使用命令行 cd到bin目录下,执行:dwebp.exe 1.webp -o 1.jpg

或者将dwebp.exe这个放入系统路径去,C:\Windows\System32\dwebp.exe

然后就可以直接运行命令了>dwebp test.webp -o a.png

 

 

 

import os
if __name__ == '__main__':
    webpTool = 'F:\\libwebp-1.0.3-windows-x64\\bin\\dwebp.exe' #工具包路径
    inDir = 'F:\\1'   #图片路径
    outDir = os.path.join(inDir, 'outPut')
    if not os.path.exists(outDir):
        os.makedirs(outDir) #创建转换图片的存放路径
    allFils = os.listdir(inDir)
    for file in allFils:
        if file.endswith('.webp'):
            outFileName = file.split('.')[0] + '.jpg' #jpg文件名
            inFile = os.path.join(inDir, file)
            outFile = os.path.join(outDir, outFileName)
            commandLine = webpTool+' '+inFile+' -o '+outFile
            os.system(commandLine)
 
posted @ 2022-11-08 11:03  也许明天  阅读(545)  评论(1编辑  收藏  举报