Re: [問題] 如何檢查圖片是否和毀損已刪文

看板Python作者 (艾爾文)時間6年前 (2019/07/29 02:18), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/7 (看更多)
那好吧。來個專屬版給你的。 from PIL import Image import os def is_valid_image(filename): valid = True try: Image.open(filename).load() except OSError: valid = False return valid YOUR_IMAGE_FOLDER = "Z://Path" # 更改成你要的資料夾 get_your_image_files = os.listdir(YOUR_IMAGE_FOLDER) for (i, get_your_image_file) in enumerate(get_your_image_files): print("Your image", i+1, get_your_image_file, ' result is: ', is_valid_image(get_your_image_file)) https://i.imgur.com/X4cG1s4.jpg
https://i.imgur.com/khZ7pIQ.jpg
※ 引述《s4028600 (佑)》之銘言: : 我在網上爬到這個 : https://www.dust8.com/2017/04/22/python-broken-image/ : 我將他給的代碼存成py檔 : 放在圖片堆中執行 : 就閃一下消失了 : 想要讀取所有資料夾下的圖片 : 或是讀取同資料夾的所有圖片 : 我要如何改造這個代碼 : 求教學 ----- Sent from JPTT on my iPhone -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.192.186.172 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1564337910.A.F13.html
文章代碼(AID): #1TFURsyJ (Python)
討論串 (同標題文章)
文章代碼(AID): #1TFURsyJ (Python)