Python introduces and uses the EXIF library for reading images,

Source: Internet
Author: User

Python introduces and uses the EXIF library for reading images,

The first thing to introduce is the Python Imaging Library. The usage is as follows:
Copy codeThe Code is 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
Handle t 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 returned list is as follows:

Copy codeThe Code is 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 is a large string of hexadecimal characters. In addition to PIL, there are many class libraries available for use:

Media Metadata for Python

EXIF. py

Python Exif Parser

A Blogger's Exif Parser

Pyexiv2


Next, let's take a look at EXIF. PY. The usage is very simple: exif. py IMG_20121122_153514.jpg
Copy codeThe Code is as follows:
EXIF ColorSpace (Short): sRGB
EXIF ComponentsConfiguration (Undefined): YCbCr
EXIF DateTimeDigitized (ASCII): 15:35:14
EXIF DateTimeOriginal (ASCII): 15:35:14
EXIF DigitalZoomRatio (Ratio): 1
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): 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 temperature interchangeformat (Long): 4970
Thumbnail temperature interchangeformatlength (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 Python Exif Parser, it seems that it has not been updated for a long time, and the usage is similar:

Copy codeThe Code is as follows:
Import exif
Photo_path = "somePath \ to \ a \ photo.jpg"
Data = exif. parse (photo_path)

You can study other class libraries on your own.




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.