function_exif.php
5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: function_exif.php 30348 2012-05-24 03:27:54Z zhengqingpeng $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
function getimageinfoval($ImageInfo,$val_arr) {
$InfoVal = exif_lang('unknown');
foreach($val_arr as $name=>$val) {
if ($name == $ImageInfo) {
$InfoVal = &$val;
break;
}
}
return $InfoVal;
}
function getexif($img) {
$imgtype = array("", "GIF", "JPG", "PNG", "SWF", "PSD", "BMP", "TIFF(intel byte order)", "TIFF(motorola byte order)", "JPC", "JP2", "JPX", "JB2", "SWC", "IFF", "WBMP", "XBM");
$Orientation = array("", "top left side", "top right side", "bottom right side", "bottom left side", "left side top", "right side top", "right side bottom", "left side bottom");
$ResolutionUnit = exif_lang('resolutionunit');
$YCbCrPositioning = array("", "the center of pixel array", "the datum point");
$ExposureProgram = exif_lang('exposureprogram');
$MeteringMode_arr = exif_lang('meteringmode');
$Lightsource_arr = exif_lang('lightsource');
$Flash_arr = array(
"0" => "flash did not fire",
"1" => "flash fired",
"5" => "flash fired but strobe return light not detected",
"7" => "flash fired and strobe return light detected",
);
if(!function_exists('exif_read_data')) {
return exif_lang('img_info');
}
$exif = @exif_read_data($img,"IFD0");
if ($exif === false) {
$new_img_info = exif_lang('img_info');
} else {
@$exif = exif_read_data($img, 0, true);
foreach($exif as $type => $typearr) {
foreach($typearr as $key => $kval) {
if(is_array($kval)) {
foreach($kval as $vkey => $value) {
$str = dhtmlspecialchars(preg_replace("/[^\[A-Za-z0-9_\.\/:\s-\]]/", '', trim($value)));
$exif[$type][$key][$vkey] = $str;
}
} elseif(!in_array($key, array('ComponentsConfiguration', 'FileSource', 'SceneType'))) {
$str = dhtmlspecialchars(preg_replace("/[^\[A-Za-z0-9_\.\/:\s-\]]/", '', trim($kval)));
$exif[$type][$key] = $str;
}
}
}
$new_img_info = array (
exif_lang('FileName') => $exif[FILE][FileName],
exif_lang('FileType') => $imgtype[$exif[FILE][FileType]],
exif_lang('MimeType') => $exif[FILE][MimeType],
exif_lang('FileSize') => $exif[FILE][FileSize],
exif_lang('FileDateTime') => date("Y-m-d H:i:s",$exif[FILE][FileDateTime]),
exif_lang('ImageDescription') => $exif[IFD0][ImageDescription],
exif_lang('Make') => $exif[IFD0][Make],
exif_lang('Model') => $exif[IFD0][Model],
exif_lang('Orientation') => $Orientation[$exif[IFD0][Orientation]],
exif_lang('XResolution') => $exif[IFD0][XResolution].$ResolutionUnit[$exif[IFD0][ResolutionUnit]],
exif_lang('YResolution') => $exif[IFD0][YResolution].$ResolutionUnit[$exif[IFD0][ResolutionUnit]],
exif_lang('Software') => $exif[IFD0][Software],
exif_lang('DateTime') => $exif[IFD0][DateTime],
exif_lang('Artist') => $exif[IFD0][Artist],
exif_lang('YCbCrPositioning') => $YCbCrPositioning[$exif[IFD0][YCbCrPositioning]],
exif_lang('Copyright') => $exif[IFD0][Copyright],
exif_lang('Photographer') => $exif[COMPUTED][Copyright.Photographer],
exif_lang('Editor') => $exif[COMPUTED][Copyright.Editor],
exif_lang('ExifVersion') => $exif[EXIF][ExifVersion],
exif_lang('FlashPixVersion') => "Ver. ".number_format($exif[EXIF][FlashPixVersion]/100,2),
exif_lang('DateTimeOriginal') => $exif[EXIF][DateTimeOriginal],
exif_lang('DateTimeDigitized') => $exif[EXIF][DateTimeDigitized],
exif_lang('Height') => $exif[COMPUTED][Height],
exif_lang('Width') => $exif[COMPUTED][Width],
exif_lang('ApertureValue') => $exif[EXIF][ApertureValue],
exif_lang('ShutterSpeedValue') => $exif[EXIF][ShutterSpeedValue],
exif_lang('ApertureFNumber') => $exif[COMPUTED][ApertureFNumber],
exif_lang('MaxApertureValue') => "F".$exif[EXIF][MaxApertureValue],
exif_lang('ExposureTime') => $exif[EXIF][ExposureTime],
exif_lang('FNumber') => $exif[EXIF][FNumber],
exif_lang('MeteringMode') => getimageinfoval($exif[EXIF][MeteringMode],$MeteringMode_arr),
exif_lang('LightSource') => getimageinfoval($exif[EXIF][LightSource], $Lightsource_arr),
exif_lang('Flash') => getimageinfoval($exif[EXIF][Flash], $Flash_arr),
exif_lang('ExposureMode') => ($exif[EXIF][ExposureMode]==1?exif_lang('manual'):exif_lang('auto')),
exif_lang('WhiteBalance') => ($exif[EXIF][WhiteBalance]==1?exif_lang('manual'):exif_lang('auto')),
exif_lang('ExposureProgram') => $ExposureProgram[$exif[EXIF][ExposureProgram]],
exif_lang('ExposureBiasValue') => $exif[EXIF][ExposureBiasValue]."EV",
exif_lang('ISOSpeedRatings') => $exif[EXIF][ISOSpeedRatings],
exif_lang('ComponentsConfiguration') => (bin2hex($exif[EXIF][ComponentsConfiguration])=="01020300"?"YCbCr":"RGB"),//'0x04,0x05,0x06,0x00'="RGB" '0x01,0x02,0x03,0x00'="YCbCr"
exif_lang('CompressedBitsPerPixel') => $exif[EXIF][CompressedBitsPerPixel]."Bits/Pixel",
exif_lang('FocusDistance') => $exif[COMPUTED][FocusDistance]."m",
exif_lang('FocalLength') => $exif[EXIF][FocalLength]."mm",
exif_lang('FocalLengthIn35mmFilm') => $exif[EXIF][FocalLengthIn35mmFilm]."mm",
exif_lang('UserCommentEncoding') => $exif[COMPUTED][UserCommentEncoding],
exif_lang('UserComment') => $exif[COMPUTED][UserComment],
exif_lang('ColorSpace') => ($exif[EXIF][ColorSpace]==1?"sRGB":"Uncalibrated"),
exif_lang('ExifImageLength') => $exif[EXIF][ExifImageLength],
exif_lang('ExifImageWidth') => $exif[EXIF][ExifImageWidth],
exif_lang('FileSource') => (bin2hex($exif[EXIF][FileSource])==0x03?"digital still camera":"unknown"),
exif_lang('SceneType') => (bin2hex($exif[EXIF][SceneType])==0x01?"A directly photographed image":"unknown"),
exif_lang('ThumbFileType') => $exif[COMPUTED][Thumbnail.FileType],
exif_lang('ThumbMimeType') => $exif[COMPUTED][Thumbnail.MimeType]
);
}
return $new_img_info;
}
function exif_lang($langkey) {
return lang('exif', $langkey);
}
?>