用途
EXIF Function是用來讀取圖片資訊使用,例如檔案類型、圖片感光資訊、圖片拍攝來源(機器)等等,算是圖片的進階資訊。
環境建置
以下文章以php5為範例
在Win32環境底下的前置作業:將 php_mbstring.dll和php_exif.dll 複製到安裝PHP的目錄
php_gd2.dll可由以下兩種來源取得:
- winntsystem32(XP是windowssystem32)通常如果沒有改extension路徑,把dll檔案丟這一樣可以執行
- 到php.netdownload 抓類似PHP 5.1.4 zip 這樣的檔案(建議使用zip安裝 or 整合好的套件, 元件比較不會有缺少的狀況)
php.ini檔中的;php_mbstring.dll和;php_exif.dll,將行首的註解字元”;”拿掉,若無此行則要新增(以前版本有可能是#符號)。
須要注意的是,php.ini內的php_mbstring.dll必須要在php_exif.dll前面,也就是說要先被載入
範例圖檔
echo “ComputerProgrammingWebPHP_LoadEFIXFromPic1.jpg:
n”;
$exif = exif_read_data(‘ComputerProgrammingWebPHP_LoadEFIXFromPic1.jpg’, ‘IFD0’);
echo $exif===false ? “No header data found.
n” : “Image contains headers
n”;
n”;
$exif = exif_read_data(‘ComputerProgrammingWebPHP_LoadEFIXFromPic1.jpg’, ‘IFD0’);
echo $exif===false ? “No header data found.
n” : “Image contains headers
n”;
$exif = exif_read_data(‘nikon.jpeg’, 0, true);
echo “ComputerProgrammingWebPHP_LoadEFIXFromPic1.jpg:
n”;
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
echo “$key.$name: $val
n”;
}
}
範例執行結果
ComputerProgrammingWebPHP_LoadEFIXFromPic1.jpg:
Image contains headers
ComputerProgrammingWebPHP_LoadEFIXFromPic1.jpg:
FILE.FileName: ComputerProgrammingWebPHP_LoadEFIXFromPic1.jpg
FILE.FileDateTime: 1152539711
FILE.FileSize: 235381
FILE.FileType: 2
FILE.MimeType: image/jpeg
FILE.SectionsFound: ANY_TAG, IFD0, THUMBNAIL, EXIF
COMPUTED.html: width=”400″ height=”533″
COMPUTED.Height: 533
COMPUTED.Width: 400
COMPUTED.IsColor: 1
COMPUTED.ByteOrderMotorola: 0
COMPUTED.ApertureFNumber: f/4.5
COMPUTED.Thumbnail.FileType: 2
COMPUTED.Thumbnail.MimeType: image/jpeg
IFD0.ImageDescription:
IFD0.Make: SONY
IFD0.Model: DSC-W5
IFD0.Orientation: 1
IFD0.XResolution: 720000/10000
IFD0.YResolution: 720000/10000
IFD0.ResolutionUnit: 2
IFD0.Software: Adobe Photoshop CS2 Windows
IFD0.DateTime: 2006:07:10 17:11:05
IFD0.YCbCrPositioning: 2
IFD0.CustomRendered: 0
IFD0.ExposureMode: 1
IFD0.WhiteBalance: 0
IFD0.SceneCaptureType: 0
IFD0.Contrast: 2
IFD0.Saturation: 2
IFD0.Sharpness: 2
IFD0.UndefinedTag:0xC4A5: PrintIM
Image contains headers
ComputerProgrammingWebPHP_LoadEFIXFromPic1.jpg:
FILE.FileName: ComputerProgrammingWebPHP_LoadEFIXFromPic1.jpg
FILE.FileDateTime: 1152539711
FILE.FileSize: 235381
FILE.FileType: 2
FILE.MimeType: image/jpeg
FILE.SectionsFound: ANY_TAG, IFD0, THUMBNAIL, EXIF
COMPUTED.html: width=”400″ height=”533″
COMPUTED.Height: 533
COMPUTED.Width: 400
COMPUTED.IsColor: 1
COMPUTED.ByteOrderMotorola: 0
COMPUTED.ApertureFNumber: f/4.5
COMPUTED.Thumbnail.FileType: 2
COMPUTED.Thumbnail.MimeType: image/jpeg
IFD0.ImageDescription:
IFD0.Make: SONY
IFD0.Model: DSC-W5
IFD0.Orientation: 1
IFD0.XResolution: 720000/10000
IFD0.YResolution: 720000/10000
IFD0.ResolutionUnit: 2
IFD0.Software: Adobe Photoshop CS2 Windows
IFD0.DateTime: 2006:07:10 17:11:05
IFD0.YCbCrPositioning: 2
IFD0.CustomRendered: 0
IFD0.ExposureMode: 1
IFD0.WhiteBalance: 0
IFD0.SceneCaptureType: 0
IFD0.Contrast: 2
IFD0.Saturation: 2
IFD0.Sharpness: 2
IFD0.UndefinedTag:0xC4A5: PrintIM