zoukankan      html  css  js  c++  java
  • Python之图片格式转换

    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)
  • 相关阅读:
    HeidiSQL
    PostgreSQL
    MariaDB
    NLog
    0 vs null
    忘带手机的那么一天
    江城子·己亥年戊辰月丁丑日话凄凉
    单体 VS 微服务
    java面向对象(四)之重写、重载
    java面向对象(三)之抽象类,接口,向上转型
  • 原文地址:https://www.cnblogs.com/huangshiyu13/p/6282816.html
Copyright © 2011-2022 走看看