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