function_exif.php 5.8 KB

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