Python is used to obtain image exif information for database instance analysis,

Source: Internet
Author: User

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.

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.