python: how to remove qualified Pictures

import os
import Image
fileName = '.....'
fp = open(fileName,'rb')
im = Image.open(fp)
fp.close()
x,y = im.size
if x <300 or y < 300:
   os.remove(fileName)

Image objects have open method did not close method, if you open a picture, the picture determine the height and width, to determine the complete picture you want to delete or rename, is inoperable, this code can solve this problem, pay attention to the image file you want to open function opens binary mode, and the parameter 'rb'

Guess you like

Origin blog.csdn.net/czp_374/article/details/90746973