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()


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM