Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
webp图片转jpg的python脚本
#!/usr/bin/python
# -*- coding: utf-8 -*-
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.replace(".webp",".jpg")
filedir = "/".join(webp.split("/")[:-1])
filedir = "%s_jpg"%filedir
if not os.path.exists(filedir):
os.makedirs(filedir)
jpg = "%s/%s"%(filedir, filename)
print("%s" %jpg)
commandline = "dwebp %s -o %s" % (webp, jpg)
os.system(commandline)
print(webp + " ------> 转换成功")
if __name__ == "__main__":
convertWebp2JpgInDirectory("/Users/haibin/talor/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.