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.