python 區分映像大小(A2、A3、A4)

來源:互聯網
上載者:User

標籤:python 區分映像大小(a2、a3、a4)

#!/usr/bin/env python
#說明,本人對象負責的項目有大量的加工映像,分別有A2 A3 A4 等規格,且這些映像都是在一起儲存,按照相關的檔案順序全組;現在讓我分別統計一共的映像數量 以及A2  A3  A4數量,經過一晚努力,現將代碼公布如下:

#這裡主要用到了Image這個模組,需要自行下載

#路徑注意事項:在Windows裡,需要將路徑中的\全部改成//



import os
import os.path
import Image
A2=0
A3=0
A4=0
total = 0

rootdir = "F://資料備份"

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 "總數如下:%d"% total
print "A2一共有:%d"% A2
print "A3一共有:%d"% A3
print "A4一共有:%d"% A4



本文出自 “劉福” 部落格,請務必保留此出處http://liufu1103.blog.51cto.com/9120722/1674197

python 區分映像大小(A2、A3、A4)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.