This example describes Python's approach to judging image integrity based on pillow. Share to everyone for your reference, specific as follows:
1, install the third party library.
2. Examples of functions.
#encoding =utf-8
#author: Walker
#date: 2016-07-26
#summary: Judging the validity of a picture
import io from
pil import Image
#判断文件是否为有效 (complete) picture
#输入参数为文件路径
def isvalidimage (pathfile):
bvalid = True
Try:
Image.open (pathfile). Verify ()
except:
bvalid = False return
bvalid
#判断文件是否为有效 (complete) Picture
# The input parameter is bytes, such as the binary data def returned by the network request
Isvalidimage4bytes (BUF):
bvalid = True
try:
image.open (IO. Bytesio (BUF)). Verify ()
except:
bvalid = False return
bvalid
More information about Python-related content can be viewed in this site: "Python picture Operation tips Summary", "Python data structure and algorithm tutorial", "Python Socket Programming Skills Summary", "Python function usage Tips", " Python string manipulation Tips Summary, Python Introductory and Advanced classic tutorials, and Python file and directory how-to tips
I hope this article will help you with Python programming.