获取指定文件夹下所有图片的名字、长和宽,长和宽,# home.zhenl
文章由Byrx.net分享于2019-03-23 10:03:59
获取指定文件夹下所有图片的名字、长和宽,长和宽,# home.zhenl
# home.zhenliang@gmail.com# http://t.qq.com/zhenliang# 获取指定文件夹下所有图片的名字、长和宽import os, sysfrom stat import *import ImagePicPathNameList = []PicWidthList = []PicHeightList = []def WalkTree(top, callback): for f in os.listdir(top): pathname = os.path.join(top, f) mode = os.stat(pathname)[ST_MODE] if S_ISDIR(mode): WalkTree(pathname, callback) elif S_ISREG(mode): callback(pathname) else: print 'Skipping %s' % pathnamedef GetPicInfo(file): global PicPathNameList global PicWidthList global PicHeightList try: image = Image.open(file) PicPathNameList.append(file) PicWidthList.append(image.size[0]) PicHeightList.append(image.size[1]) except IOError: passif __name__ == '__main__': WalkTree(top, GetPicInfo) print "PicPathNameList Begin" print PicPathNameList print PicWidthList print PicHeightList print "PicPathNameList End"
评论关闭