Python Read pictures Exif Information Class Library introduction and Usages _python

Source: Internet
Author: User
Tags datetime

The first thing to introduce is the Python Imaging Library, using the following methods:

Copy Code code as follows:

From PIL import Image
From PiL. Exiftags Import TAGS

def get_exif_data (fname):
"" "Get embedded EXIF data from image file." "
ret = {}
Try
img = Image.open (fname)
If Hasattr (IMG, ' _getexif '):
Exifinfo = Img._getexif ()
If Exifinfo!= None:
For tag, value in Exifinfo.items ():
decoded = Tags.get (tag, tag)
Ret[decoded] = value
Except IOError:
print ' IOError ' + fname
return ret

if __name__ = = ' __main__ ':
FileName = ' c:/users/leyond/desktop/img_20121122_153514.jpg '
EXIF = Get_exif_data (fileName)
Print EXIF


The list returned is as follows:

Copy Code code as follows:

Exifversion
Componentsconfiguration
Exifimagewidth
Datetimeoriginal
Datetimedigitized
Exifinteroperabilityoffset
Flashpixversion
Meteringmode
LightSource
Flash
Focallength
41986
Imagedescription
Make
Model
Orientation
Ycbcrpositioning
41988
XResolution
YResolution
59932
Exposuretime
Exposureprogram
ColorSpace
41990
Isospeedratings
Resolutionunit
41987
Fnumber
Software
Datetime
Exifimageheight
Exifoffset

59932 of them, is a large string of hexadecimal characters, do not know why. In addition to PIL, there are many class libraries to use:

Media Metadata for Python

exif.py

Python Exif Parser

A Blogger ' s Exif Parser

Pyexiv2


Then look at the exif.py, the use of the method is very simple: exif.py img_20121122_153514.jpg

Copy Code code as follows:

EXIF ColorSpace (short): SRGB
EXIF componentsconfiguration (Undefined): YCbCr
EXIF datetimedigitized (ASCII): 2012:11:22 15:35:14
EXIF datetimeoriginal (ASCII): 2012:11:22 15:35:14
EXIF Digitalzoomratio (Ratio): 1
EXIF exifimagelength (Long): 2560
EXIF exifimagewidth (Long): 1920
EXIF exifversion (Undefined): 0220
EXIF Exposurebiasvalue (signed Ratio): 0
EXIF Exposuremode (short): Auto exposure
EXIF Exposureprogram (short): Portrait Mode
EXIF Exposuretime (Ratio): 1/256
EXIF Fnumber (Ratio): 14/5
EXIF Flash (short): Flash did not fire
EXIF flashpixversion (Undefined): 0100
EXIF focallength (Ratio): 35
EXIF isospeedratings (short): 56
EXIF Interoperabilityoffset (Long): 4810
EXIF LightSource (short): Other light source
EXIF Meteringmode (short): Centerweightedaverage
EXIF Padding (Undefined): []
EXIF Scenecapturetype (short): Portrait
EXIF whitebalance (short): Auto
Image DateTime (ASCII): 2012:11:24 09:44:50
Image Exifoffset (Long): 2396
Image imagedescription (ASCII):
Image make (ASCII):
Image Model (ASCII):
Image Orientation (short): Horizontal (normal)
Image Padding (Undefined): []
Image Resolutionunit (short): Pixels/inch
Image Software (ASCII): Microsoft Windows Photo Viewer 6.1.7600.16385
Image xresolution (Ratio): 72
Image ycbcrpositioning (short): co-sited
Image yresolution (Ratio): 72
Thumbnail Compression (short): JPEG (Old-style)
Thumbnail Jpeginterchangeformat (Long): 4970
Thumbnail jpeginterchangeformatlength (Long): 3883
Thumbnail Orientation (short): Horizontal (normal)
Thumbnail Resolutionunit (short): Pixels/inch
Thumbnail xresolution (Ratio): 72
Thumbnail ycbcrpositioning (short): co-sited
Thumbnail yresolution (Ratio): 72

As for the Python Exif Parser, it seems like it hasn't been updated for a long time, and the usage is similar:

Copy Code code as follows:

Import EXIF
Photo_path = "Somepath\to\a\photo.jpg"
data = Exif.parse (Photo_path)

Other libraries please study for yourself.

Related Article

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.