Python之图片格式转换(python将png图片转为jpg)

网友投稿 391 2022-08-24


Python之图片格式转换(python将png图片转为jpg)

import osimport shutilfrom PIL import Imagedef 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 resultsdef 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)

黄世宇/Shiyu Huang's Personal Page:​​https://huangshiyu13.github.io/​​


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Python之json(PYthon)
下一篇:手写简版kedis分布式key及value服务的实现及配置
相关文章

 发表评论

暂时没有评论,来抢沙发吧~