码迷,mamicode.com
首页 > 编程语言 > 详细

Python之图片格式转换

时间:2017-01-13 15:54:54      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:eps   ima   result   imp   mtr   images   print   turn   main   

import os
import shutil
from PIL import Image

def getAllFiles(dirName, houzhui= ):
    results = []

    for file in os.listdir(dirName):
        file_path = os.path.join(dirName, file)
        if houzhui ==  :
            if os.path.isfile(file_path):
                results.append([file_path, os.path.splitext(file)[0]])
        else:
            if os.path.isfile(file_path) and os.path.splitext(file_path)[1] == houzhui:
                results.append([file_path,os.path.splitext(file)[0]])
    return results


def checkFile(fileName):
    if os.path.isfile(fileName):
        return True
    else:
        print fileName, is not found!
        exit()


def checkDir(fileName, creat=False):
    if os.path.isdir(fileName):
        if creat:
            shutil.rmtree(fileName)
            os.mkdir(fileName)
    else:
        if creat:
            os.mkdir(fileName)
        else:
            print fileName, is not found!
            exit()


if __name__ == __main__:
    files = getAllFiles(./images/,.jpg)
    for file in files:
        fileName = file[0]
        fileShortName = file[1]
        saveFileName = ./images/+fileShortName+.eps
        Image.open(fileName).save(saveFileName)

 

Python之图片格式转换

标签:eps   ima   result   imp   mtr   images   print   turn   main   

原文地址:http://www.cnblogs.com/huangshiyu13/p/6282816.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!