Python distinguishes image size (A2, A3, A4)

Source: Internet
Author: User

#!/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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.