首页 > 代码库 > Python之图片格式转换
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)
Python之图片格式转换
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。