假设图像的"大小"是其面积:
from PIL import Image
def get_img_size(path):
width, height = Image.open(path).size
return width*height
largest = max(the_paths, key=get_img_size)
Run Code Online (Sandbox Code Playgroud)
使用Python Imaging Library(PIL).像这样的东西:
from PIL import Image
filenames = ['/home/you/Desktop/chstamp.jpg', '/home/you/Desktop/something.jpg']
sizes = [Image.open(f, 'r').size for f in filenames]
max(sizes)
Run Code Online (Sandbox Code Playgroud)
更新(谢谢德尔南):
将以上代码段的最后两行替换为:
max(Image.open(f, 'r').size for f in filenames)
Run Code Online (Sandbox Code Playgroud)
更新2
OP想要找到与最大尺寸对应的文件的索引.这需要一些帮助numpy.见下文:
from numpy import array
image_array = array([Image.open(f, 'r').size for f in filenames])
print image_array.argmax()
Run Code Online (Sandbox Code Playgroud)