Python's method for judging image integrity based on pillow _python

Source: Internet
Author: User

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.

Pip Install Pillow

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.

Related Article

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.