webp to png 批量操作
首先下载webp包,对应各个平台都有,链接请见:https://developers.google.com/speed/webp/
参考批量代码:
import os
import time
# 遍历指定目录,显示目录下的所有文件名
def convertWebp2JpgInDirectory(dir):
if os.path.isdir(dir):
allfiles = os.listdir(dir)
for fi in allfiles:
fi_d = os.path.join(dir, fi)
if os.path.isdir(fi_d):
convertWebp2JpgInDirectory(fi_d)
else:
if fi_d.endswith(".webp"):
webp = os.path.join(dir, fi_d)
filename = webp.split("/")[-1]
filename = filename.split(".")[0]
filedir = "/".join(webp.split("/")[:-1])
filedir = "%s_jpg"%filedir
if not os.path.exists(filedir):
os.makedirs(filedir)
jpg = "%s/%s"%(filedir, filename)
commandline = "dwebp %s -o %s.jpg" % (webp, jpg)
os.system(commandline)
print(webp + " ------> 转换成功")
if __name__ == "__main__":
convertWebp2JpgInDirectory("/home/xxx/subfolder")

浙公网安备 33010602011771号