python修改图片格式

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
from wand.image import Image
from struct import *

def pdfToPng():
path = "/home/siyin/素材库各20例/"
listdir = os.listdir(path)
print listdir
for dir in listdir:
basePath = path + dir + "/"
savePath = "/home/siyin/素材库各20例(png)/" + dir + "/"
if os.path.exists(savePath) == False:
os.mkdir(savePath)
fileList = os.listdir(basePath)
for file in fileList:
filePath = basePath + file
print filePath
newFileName = file.split(".")[0]
with Image(filename=filePath) as img:
if(file.split(".")[1] == "png" ):
img.save(filename=savePath+file)
else:
img.save(filename=savePath + newFileName + ".png" )
os.remove(filePath)
if __name__ == "__main__":
pdfToPng()

posted @ 2017-06-21 10:24  三里路异乡客  阅读(2360)  评论(0编辑  收藏  举报