Created
July 28, 2018 13:11
-
-
Save haibinpark/b95d9ffec00446b09fcfba5c914b8532 to your computer and use it in GitHub Desktop.
webp图片转jpg的python脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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