如何用Python方法获取图片的准确尺寸,,Python如何获取图片


Python如何获取图片长宽等信息?Python图形界面的操作过程中,尺寸是一个很重要的问题。那如何用Python方法获取图片的准确尺寸,这样的Python教程源码要如何编写,下面就来为大家提供一个关于获取目标图片尺寸的Python源码方法示例。

如何用Python方法获取图片的准确尺寸方法源码如下:(仅供给大家一个参考)

#导入方法模块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' % pathname#www.iplaypy.comdef 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"

编橙之家Python源码中,在使用Python实现自动提取国家地理每日图片的方法时,你可以把这个方法融入其中,顺便计算出它的尺寸也是很不错的。

编橙之家文章,

评论关闭