Python is used to obtain image exif information for database instance analysis,
This example describes how to use python to obtain image exif information. 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.
Copy codeThe 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.