#!/usr/bin/env python
#说明, I am responsible for the project has a large number of processing images, respectively, A2 A3 A4 and other specifications, and these images are stored together, in accordance with the relevant file sequence of the whole group; now let me count the total number of images and A2 A3 A4, after a night of effort, the code is now published as follows:
#这里主要用到了Image这个模块, you need to download it yourself
#路径注意事项: In Windows, you need to change \ All in the path to//
Import OS
Import Os.path
Import Image
A2=0
A3=0
A4=0
Total = 0
RootDir = "f://Data Backup"
For Parent,dirnames,filenames in Os.walk (ROOTDIR):
Print Dirnames
If Len (filenames) > 0 and len (dirnames) = = 0:
For I in range (len (filenames)):
filename = parent + "//" + filenames[i]
Print filename
If Filename.find (". jpg") > 0:
Image = Image.open (filename)
Image_size = image.size[0]
Total+=1
If Image_size <= 3500:
A4 = A4 + 1
Elif image_size > 3501 and image_size <= 6000:
A3 = A3 + 1
Elif image_size >= 6000:
A2 = A2 + 1
Print "Totals are as follows:%d"% total
Print "A2 altogether has:%d"% A2
Print "A3 altogether has:%d"% A3
Print "A4 altogether has:%d"% A4
This article is from the "Zhengerniu" blog, make sure to keep this source http://liufu1103.blog.51cto.com/9120722/1674197
Python distinguishes image size (A2, A3, A4)