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.