PHP中读取照片exif信息的方法(2)

extension = "mbstring.so"
extension = "exif.so"


并且确认你的extension_dir值与你安装模块时提示的Installing shared extensions值一致,比如我安装模块时提示我的extensions位置是

复制代码 代码如下:

/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/


那么你的php.ini里的extension_dir要指向正确目录

复制代码 代码如下:

extension_dir="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/"


保存php.ini,重启webserver。
打开phpinfo()找到相应属性看看是否已正常工作

正常情况下你会看到如下两个模块信息

PHP中读取照片exif信息的方法

PHP中读取照片exif信息的方法

使用exif_read_data()读取图片的exif信息

支持读取exif信息的图片类型在phpinfo里已经写明了,只能是jpeg或者tiff类型,其中jpeg是常用类型,这就已经足够。
我们来看看exif_read_data()函数的使用手册

复制代码 代码如下:


array exif_read_data ( string $filename [, string $sections = NULL [, bool $arrays = false [, bool $thumbnail = false ]]] )

参数:

filename :要读取图片exif信息的图片路径,这里不能是URL
sections:是需要存在于文件中的逗号分隔的区段列表用来产生结果数组。如果未找到所请求的区段则返回值为 FALSE。

FILE   FileName, FileSize, FileDateTime, SectionsFound  
COMPUTED   html,Width,Height,IsColor,可能有更多其它的。Height 和 Width 是用和 getimagesize() 一样的方法计算的,因此它们的值不能是任何返回的头信息的部分。此外 html 是一个 height/width 的文本字符串可以用于普通的HTML 中。  
ANY_TAG   任何包含有标记的信息,例如 IFD0,EXIF,...  
IFD0   所有 IFD0 的标记数据。在标准的图像文件中这包含了图像大小及其它。  
THUMBNAIL   如果有第二个 IFD,文件应该包含有缩略图。所有有关嵌入缩略图的标记信息都存储在本区。  
COMMENT   JPEG 图像的注释头信息。  
EXIF   EXIF 区段是 IFDO 的子区,包含有图像的更多详细信息。大多数内容都是数码相机相关的。  

arrays :指定了是否每个区段都成为一个数组。sections COMPUTED,THUMBNAIL 和COMMENT 区段总是成为数组,因为它们里面包含的名字和其它区段冲突。

thumbnail : 当设定为 TRUE 时,读取缩略图本身。否则只读取标记数据。
 
我们来读取一张图片的exif信息试试

复制代码 代码如下:


<?php
$exif = getExif('a.jpg');
echo '<pre>';
print_r($exif);
echo '</pre>';


执行结果:

复制代码 代码如下:


Array
(
    [FileName] => a.jpg
    [FileDateTime] => 1361340032
    [FileSize] => 69170
    [FileType] => 2
    [MimeType] => image/jpeg
    [SectionsFound] => ANY_TAG, IFD0, THUMBNAIL, EXIF, GPS, INTEROP
    [COMPUTED] => Array
        (
            [html] =>
            [Height] => 397
            [Width] => 600
            [IsColor] => 1
            [ByteOrderMotorola] => 1
            [ApertureFNumber] => f/13.0
            [FocusDistance] => 3.76m
            [UserComment] =>
            [UserCommentEncoding] => ASCII
            [Copyright] =>                                                     
            [Thumbnail.FileType] => 2
            [Thumbnail.MimeType] => image/jpeg
        )
    [ImageWidth] => 4928
    [ImageLength] => 3264
    [BitsPerSample] => Array
        (
            [0] => 8
            [1] => 8
            [2] => 8
        )
    [PhotometricInterpretation] => 2
    [Make] => NIKON CORPORATION
    [Model] => NIKON D7000
    [Orientation] => 1
    [SamplesPerPixel] => 3
    [XResolution] => 3000000/10000
    [YResolution] => 3000000/10000
    [ResolutionUnit] => 2
    [Software] => Adobe Photoshop CS5 Windows
    [DateTime] => 2013:02:18 20:50:46
    [WhitePoint] => Array
        (
            [0] => 313/1000
            [1] => 329/1000
        )
    [PrimaryChromaticities] => Array
        (
            [0] => 64/100
            [1] => 33/100
            [2] => 21/100
            [3] => 71/100
            [4] => 15/100
            [5] => 6/100
        )
    [YCbCrCoefficients] => Array
        (
            [0] => 299/1000
            [1] => 587/1000
            [2] => 114/1000
        )
    [YCbCrPositioning] => 2
    [Copyright] =>                                                     
    [Exif_IFD_Pointer] => 500
    [GPS_IFD_Pointer] => 1248
    [THUMBNAIL] => Array
        (
            [Compression] => 6
            [XResolution] => 72/1
            [YResolution] => 72/1
            [ResolutionUnit] => 2
            [JPEGInterchangeFormat] => 1362
            [JPEGInterchangeFormatLength] => 4784
        )
    [ExposureTime] => 40/10
    [FNumber] => 130/10
    [ExposureProgram] => 1
    [ISOSpeedRatings] => 1000
    [UndefinedTag:0x8830] => 2
    [ExifVersion] => 0230
    [DateTimeOriginal] => 2013:02:14 21:12:08
    [DateTimeDigitized] => 2013:02:14 21:12:08
    [ComponentsConfiguration] => 
    [CompressedBitsPerPixel] => 4/1
    [ShutterSpeedValue] => -2/1
    [ApertureValue] => 7400879/1000000
    [ExposureBiasValue] => 2/6
    [MaxApertureValue] => 36/10
    [SubjectDistance] => 376/100
    [MeteringMode] => 3
    [LightSource] => 0
    [Flash] => 16
    [FocalLength] => 180/10
    [UserComment] => ASCII
    [SubSecTime] => 10
    [SubSecTimeOriginal] => 10
    [SubSecTimeDigitized] => 10
    [FlashPixVersion] => 0100
    [ColorSpace] => 65535
    [ExifImageWidth] => 600
    [ExifImageLength] => 397
    [InteroperabilityOffset] => 1216
    [SensingMethod] => 2
    [FileSource] => 
    [SceneType] => 
    [CFAPattern] => 
    [CustomRendered] => 0
    [ExposureMode] => 1
    [WhiteBalance] => 0
    [DigitalZoomRatio] => 1/1
    [FocalLengthIn35mmFilm] => 27
    [SceneCaptureType] => 0
    [GainControl] => 2
    [Contrast] => 0
    [Saturation] => 0
    [Sharpness] => 0
    [SubjectDistanceRange] => 0
    [UndefinedTag:0xA500] => 22/10
    [GPSVersion] => 
    [InterOperabilityIndex] => R03
    [InterOperabilityVersion] => 0100
)

如果提示:

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/e808af623403e0d71554681d3988b7f3.html