A library instance analysis used by Python to obtain image EXIF information

Source: Internet
Author: User
This example describes the library usage that Python uses to obtain EXIF information for a picture. Share to everyone for your reference. The specific analysis is as follows:

Exif-py is a purely Python-implemented Python library for picture metadata, the official download address:
Http://exif-py.svn.sourceforge.net/viewvc/exif-py/source/EXIF.py?revision=19&view=markup

The following code shows the calling method.
Copy the Code code as follows:

# library Test/debug function (dump given files)
if __name__ = = ' __main__ ':
Import Sys
Import getopt
# Parse command line options/arguments
Try
opts, args = Getopt.getopt (sys.argv[1:], "hqsdt:v", ["Help", "quick", "strict", "Debug", "stop-tag="])
Except Getopt. Getopterror:
Usage (2)
if args = = []:
Usage (2)
Detailed = True
Stop_tag = ' UNDEF '
debug = False
Strict = False
For O, the A in opts:
If O in ("-H", "--help"):
Usage (0)
If O in ("-Q", "--quick"):
Detailed = False
If O in ("-T", "--stop-tag"):
Stop_tag = A
If O in ("-S", "--strict"):
Strict = True
If O in ("-D", "--debug"):
debug = True
# output info for each file
For filename in args:
Try
File=open (filename, ' RB ')
Except
Print "'%s ' is unreadable\n"%filename
Continue
Print filename + ': '
# Get the tags
data = process_file (file, Stop_tag=stop_tag, details=detailed, Strict=strict, Debug=debug)
If not data:
print ' No EXIF information found '
Continue
X=data.keys ()
X.sort ()
For I in x:
If I in (' Jpegthumbnail ', ' Tiffthumbnail '):
Continue
Try
print '%s ' (%s):%s '% \
(I, field_types[data[i].field_type][2], data[i].printable)
Except
print ' Error ', I, ' "', Data[i], '" '
If ' Jpegthumbnail ' in data:
print ' File has JPEG thumbnail '
Print

Hopefully this article will help you with Python programming.

  • 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.