Python is used to obtain Image exif information for database instance analysis-Python tutorial

Source: Internet
Author: User
This article mainly introduces the python library used to obtain Image exif information. The example analyzes the usage skills of the exif-py library file, which has some reference value, for more information about how to use python to obtain Image exif information, see the following example. Share it with you for your reference. The specific analysis is as follows:

Exif-py is a python library that is implemented in pure python to obtain image metadata. official website:
Http://exif-py.svn.sourceforge.net/viewvc/exif-py/source/EXIF.py? Revision = 19 & view = markup

The following code demonstrates the call method.

The code is 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 ="])
Counter T getopt. GetoptError:
Usage (2)
If args = []:
Usage (2)
Detailed = True
Stop_tag = 'undef'
Debug = False
Strict = False
For o, 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 =
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 t:
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 ('your thumbnail ', 'Your thumbnail '):
Continue
Try:
Print '% s (% s): % s' % \
(I, FIELD_TYPES [data [I]. field_type] [2], data [I]. printable)
Except t:
Print 'error', I, '"', data [I], '"'
If 'processing thumbnail 'in data:
Print 'file has JPEG thumbnail'
Print

I hope 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.