module.graphic.jpg.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org> //
  4. // available at http://getid3.sourceforge.net //
  5. // or http://www.getid3.org //
  6. /////////////////////////////////////////////////////////////////
  7. // See readme.txt for more details //
  8. /////////////////////////////////////////////////////////////////
  9. // //
  10. // module.graphic.jpg.php //
  11. // module for analyzing JPEG Image files //
  12. // dependencies: NONE //
  13. // ///
  14. /////////////////////////////////////////////////////////////////
  15. class getid3_jpg
  16. {
  17. function getid3_jpg(&$fd, &$ThisFileInfo) {
  18. $ThisFileInfo['fileformat'] = 'jpg';
  19. $ThisFileInfo['video']['dataformat'] = 'jpg';
  20. $ThisFileInfo['video']['lossless'] = false;
  21. $ThisFileInfo['video']['bits_per_sample'] = 24;
  22. $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1;
  23. fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
  24. $imageinfo = array();
  25. list($width, $height, $type) = getid3_lib::GetDataImageSize(fread($fd, $ThisFileInfo['filesize']), $imageinfo);
  26. if (isset($imageinfo['APP13'])) {
  27. // http://php.net/iptcparse
  28. // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html
  29. $iptc_parsed = iptcparse($imageinfo['APP13']);
  30. if (is_array($iptc_parsed)) {
  31. foreach ($iptc_parsed as $iptc_key_raw => $iptc_values) {
  32. list($iptc_record, $iptc_tagkey) = explode('#', $iptc_key_raw);
  33. $iptc_tagkey = intval(ltrim($iptc_tagkey, '0'));
  34. foreach ($iptc_values as $key => $value) {
  35. @$ThisFileInfo['iptc'][$this->IPTCrecordName($iptc_record)][$this->IPTCrecordTagName($iptc_record, $iptc_tagkey)][] = $value;
  36. }
  37. }
  38. }
  39. //echo '<pre>'.htmlentities(print_r($iptc_parsed, true)).'</pre>';
  40. }
  41. switch ($type) {
  42. case 2: // JPEG
  43. $ThisFileInfo['video']['resolution_x'] = $width;
  44. $ThisFileInfo['video']['resolution_y'] = $height;
  45. if (version_compare(phpversion(), '4.2.0', '>=')) {
  46. if (function_exists('exif_read_data')) {
  47. ob_start();
  48. $ThisFileInfo['jpg']['exif'] = exif_read_data($ThisFileInfo['filenamepath'], '', true, false);
  49. $errors = ob_get_contents();
  50. if ($errors) {
  51. $ThisFileInfo['warning'][] = strip_tags($errors);
  52. unset($ThisFileInfo['jpg']['exif']);
  53. }
  54. ob_end_clean();
  55. } else {
  56. $ThisFileInfo['warning'][] = 'EXIF parsing only available when '.(GETID3_OS_ISWINDOWS ? 'php_exif.dll enabled' : 'compiled with --enable-exif');
  57. }
  58. } else {
  59. $ThisFileInfo['warning'][] = 'EXIF parsing only available in PHP v4.2.0 and higher compiled with --enable-exif (or php_exif.dll enabled for Windows). You are using PHP v'.phpversion();
  60. }
  61. return true;
  62. break;
  63. default:
  64. break;
  65. }
  66. unset($ThisFileInfo['fileformat']);
  67. return false;
  68. }
  69. function IPTCrecordName($iptc_record) {
  70. // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html
  71. static $IPTCrecordName = array();
  72. if (empty($IPTCrecordName)) {
  73. $IPTCrecordName = array(
  74. 1 => 'IPTCEnvelope',
  75. 2 => 'IPTCApplication',
  76. 3 => 'IPTCNewsPhoto',
  77. 7 => 'IPTCPreObjectData',
  78. 8 => 'IPTCObjectData',
  79. 9 => 'IPTCPostObjectData',
  80. );
  81. }
  82. return (isset($IPTCrecordName[$iptc_record]) ? $IPTCrecordName[$iptc_record] : '');
  83. }
  84. function IPTCrecordTagName($iptc_record, $iptc_tagkey) {
  85. // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html
  86. static $IPTCrecordTagName = array();
  87. if (empty($IPTCrecordTagName)) {
  88. $IPTCrecordTagName = array(
  89. 1 => array( // IPTC EnvelopeRecord Tags
  90. 0 => 'EnvelopeRecordVersion',
  91. 5 => 'Destination',
  92. 20 => 'FileFormat',
  93. 22 => 'FileVersion',
  94. 30 => 'ServiceIdentifier',
  95. 40 => 'EnvelopeNumber',
  96. 50 => 'ProductID',
  97. 60 => 'EnvelopePriority',
  98. 70 => 'DateSent',
  99. 80 => 'TimeSent',
  100. 90 => 'CodedCharacterSet',
  101. 100 => 'UniqueObjectName',
  102. 120 => 'ARMIdentifier',
  103. 122 => 'ARMVersion',
  104. ),
  105. 2 => array( // IPTC ApplicationRecord Tags
  106. 0 => 'ApplicationRecordVersion',
  107. 3 => 'ObjectTypeReference',
  108. 4 => 'ObjectAttributeReference',
  109. 5 => 'ObjectName',
  110. 7 => 'EditStatus',
  111. 8 => 'EditorialUpdate',
  112. 10 => 'Urgency',
  113. 12 => 'SubjectReference',
  114. 15 => 'Category',
  115. 20 => 'SupplementalCategories',
  116. 22 => 'FixtureIdentifier',
  117. 25 => 'Keywords',
  118. 26 => 'ContentLocationCode',
  119. 27 => 'ContentLocationName',
  120. 30 => 'ReleaseDate',
  121. 35 => 'ReleaseTime',
  122. 37 => 'ExpirationDate',
  123. 38 => 'ExpirationTime',
  124. 40 => 'SpecialInstructions',
  125. 42 => 'ActionAdvised',
  126. 45 => 'ReferenceService',
  127. 47 => 'ReferenceDate',
  128. 50 => 'ReferenceNumber',
  129. 55 => 'DateCreated',
  130. 60 => 'TimeCreated',
  131. 62 => 'DigitalCreationDate',
  132. 63 => 'DigitalCreationTime',
  133. 65 => 'OriginatingProgram',
  134. 70 => 'ProgramVersion',
  135. 75 => 'ObjectCycle',
  136. 80 => 'By-line',
  137. 85 => 'By-lineTitle',
  138. 90 => 'City',
  139. 92 => 'Sub-location',
  140. 95 => 'Province-State',
  141. 100 => 'Country-PrimaryLocationCode',
  142. 101 => 'Country-PrimaryLocationName',
  143. 103 => 'OriginalTransmissionReference',
  144. 105 => 'Headline',
  145. 110 => 'Credit',
  146. 115 => 'Source',
  147. 116 => 'CopyrightNotice',
  148. 118 => 'Contact',
  149. 120 => 'Caption-Abstract',
  150. 121 => 'LocalCaption',
  151. 122 => 'Writer-Editor',
  152. 125 => 'RasterizedCaption',
  153. 130 => 'ImageType',
  154. 131 => 'ImageOrientation',
  155. 135 => 'LanguageIdentifier',
  156. 150 => 'AudioType',
  157. 151 => 'AudioSamplingRate',
  158. 152 => 'AudioSamplingResolution',
  159. 153 => 'AudioDuration',
  160. 154 => 'AudioOutcue',
  161. 184 => 'JobID',
  162. 185 => 'MasterDocumentID',
  163. 186 => 'ShortDocumentID',
  164. 187 => 'UniqueDocumentID',
  165. 188 => 'OwnerID',
  166. 200 => 'ObjectPreviewFileFormat',
  167. 201 => 'ObjectPreviewFileVersion',
  168. 202 => 'ObjectPreviewData',
  169. 221 => 'Prefs',
  170. 225 => 'ClassifyState',
  171. 228 => 'SimilarityIndex',
  172. 230 => 'DocumentNotes',
  173. 231 => 'DocumentHistory',
  174. 232 => 'ExifCameraInfo',
  175. ),
  176. 3 => array( // IPTC NewsPhoto Tags
  177. 0 => 'NewsPhotoVersion',
  178. 10 => 'IPTCPictureNumber',
  179. 20 => 'IPTCImageWidth',
  180. 30 => 'IPTCImageHeight',
  181. 40 => 'IPTCPixelWidth',
  182. 50 => 'IPTCPixelHeight',
  183. 55 => 'SupplementalType',
  184. 60 => 'ColorRepresentation',
  185. 64 => 'InterchangeColorSpace',
  186. 65 => 'ColorSequence',
  187. 66 => 'ICC_Profile',
  188. 70 => 'ColorCalibrationMatrix',
  189. 80 => 'LookupTable',
  190. 84 => 'NumIndexEntries',
  191. 85 => 'ColorPalette',
  192. 86 => 'IPTCBitsPerSample',
  193. 90 => 'SampleStructure',
  194. 100 => 'ScanningDirection',
  195. 102 => 'IPTCImageRotation',
  196. 110 => 'DataCompressionMethod',
  197. 120 => 'QuantizationMethod',
  198. 125 => 'EndPoints',
  199. 130 => 'ExcursionTolerance',
  200. 135 => 'BitsPerComponent',
  201. 140 => 'MaximumDensityRange',
  202. 145 => 'GammaCompensatedValue',
  203. ),
  204. 7 => array( // IPTC PreObjectData Tags
  205. 10 => 'SizeMode',
  206. 20 => 'MaxSubfileSize',
  207. 90 => 'ObjectSizeAnnounced',
  208. 95 => 'MaximumObjectSize',
  209. ),
  210. 8 => array( // IPTC ObjectData Tags
  211. 10 => 'SubFile',
  212. ),
  213. 9 => array( // IPTC PostObjectData Tags
  214. 10 => 'ConfirmedObjectSize',
  215. ),
  216. );
  217. }
  218. return (isset($IPTCrecordTagName[$iptc_record][$iptc_tagkey]) ? $IPTCrecordTagName[$iptc_record][$iptc_tagkey] : $iptc_tagkey);
  219. }
  220. }
  221. ?>