PageRenderTime 53ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/common/libraries/plugin/getid3/module.graphic.jpg.php

https://bitbucket.org/chamilo/chamilo-dev/
PHP | 173 lines | 130 code | 25 blank | 18 comment | 8 complexity | 18db9eee49ff9e0073ee6d3829ec8b2e MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT
  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 __construct(&$fd, &$ThisFileInfo)
  18. {
  19. $ThisFileInfo['fileformat'] = 'jpg';
  20. $ThisFileInfo['video']['dataformat'] = 'jpg';
  21. $ThisFileInfo['video']['lossless'] = false;
  22. $ThisFileInfo['video']['bits_per_sample'] = 24;
  23. $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1;
  24. fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
  25. $imageinfo = array();
  26. list($width, $height, $type) = getid3_lib :: GetDataImageSize(fread($fd, $ThisFileInfo['filesize']), $imageinfo);
  27. if (isset($imageinfo['APP13']))
  28. {
  29. // http://php.net/iptcparse
  30. // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html
  31. $iptc_parsed = iptcparse($imageinfo['APP13']);
  32. if (is_array($iptc_parsed))
  33. {
  34. foreach ($iptc_parsed as $iptc_key_raw => $iptc_values)
  35. {
  36. list($iptc_record, $iptc_tagkey) = explode('#', $iptc_key_raw);
  37. $iptc_tagkey = intval(ltrim($iptc_tagkey, '0'));
  38. foreach ($iptc_values as $key => $value)
  39. {
  40. @$ThisFileInfo['iptc'][$this->IPTCrecordName($iptc_record)][$this->IPTCrecordTagName($iptc_record, $iptc_tagkey)][] = $value;
  41. }
  42. }
  43. }
  44. //echo '<pre>'.htmlentities(print_r($iptc_parsed, true)).'</pre>';
  45. }
  46. switch ($type)
  47. {
  48. case 2 : // JPEG
  49. $ThisFileInfo['video']['resolution_x'] = $width;
  50. $ThisFileInfo['video']['resolution_y'] = $height;
  51. if (version_compare(phpversion(), '4.2.0', '>='))
  52. {
  53. if (function_exists('exif_read_data'))
  54. {
  55. ob_start();
  56. $ThisFileInfo['jpg']['exif'] = exif_read_data($ThisFileInfo['filenamepath'], '', true, false);
  57. $errors = ob_get_contents();
  58. if ($errors)
  59. {
  60. $ThisFileInfo['warning'][] = strip_tags($errors);
  61. unset($ThisFileInfo['jpg']['exif']);
  62. }
  63. ob_end_clean();
  64. }
  65. else
  66. {
  67. $ThisFileInfo['warning'][] = 'EXIF parsing only available when ' . (GETID3_OS_ISWINDOWS ? 'php_exif.dll enabled' : 'compiled with --enable-exif');
  68. }
  69. }
  70. else
  71. {
  72. $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();
  73. }
  74. return true;
  75. break;
  76. default :
  77. break;
  78. }
  79. unset($ThisFileInfo['fileformat']);
  80. return false;
  81. }
  82. function IPTCrecordName($iptc_record)
  83. {
  84. // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html
  85. static $IPTCrecordName = array();
  86. if (empty($IPTCrecordName))
  87. {
  88. $IPTCrecordName = array(1 => 'IPTCEnvelope', 2 => 'IPTCApplication', 3 => 'IPTCNewsPhoto',
  89. 7 => 'IPTCPreObjectData', 8 => 'IPTCObjectData', 9 => 'IPTCPostObjectData');
  90. }
  91. return (isset($IPTCrecordName[$iptc_record]) ? $IPTCrecordName[$iptc_record] : '');
  92. }
  93. function IPTCrecordTagName($iptc_record, $iptc_tagkey)
  94. {
  95. // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html
  96. static $IPTCrecordTagName = array();
  97. if (empty($IPTCrecordTagName))
  98. {
  99. $IPTCrecordTagName = array(
  100. 1 => array(// IPTC EnvelopeRecord Tags
  101. 0 => 'EnvelopeRecordVersion', 5 => 'Destination', 20 => 'FileFormat',
  102. 22 => 'FileVersion', 30 => 'ServiceIdentifier', 40 => 'EnvelopeNumber', 50 => 'ProductID',
  103. 60 => 'EnvelopePriority', 70 => 'DateSent', 80 => 'TimeSent', 90 => 'CodedCharacterSet',
  104. 100 => 'UniqueObjectName', 120 => 'ARMIdentifier', 122 => 'ARMVersion'),
  105. 2 => array(// IPTC ApplicationRecord Tags
  106. 0 => 'ApplicationRecordVersion', 3 => 'ObjectTypeReference',
  107. 4 => 'ObjectAttributeReference', 5 => 'ObjectName', 7 => 'EditStatus',
  108. 8 => 'EditorialUpdate', 10 => 'Urgency', 12 => 'SubjectReference', 15 => 'Category',
  109. 20 => 'SupplementalCategories', 22 => 'FixtureIdentifier', 25 => 'Keywords',
  110. 26 => 'ContentLocationCode', 27 => 'ContentLocationName', 30 => 'ReleaseDate',
  111. 35 => 'ReleaseTime', 37 => 'ExpirationDate', 38 => 'ExpirationTime',
  112. 40 => 'SpecialInstructions', 42 => 'ActionAdvised', 45 => 'ReferenceService',
  113. 47 => 'ReferenceDate', 50 => 'ReferenceNumber', 55 => 'DateCreated', 60 => 'TimeCreated',
  114. 62 => 'DigitalCreationDate', 63 => 'DigitalCreationTime', 65 => 'OriginatingProgram',
  115. 70 => 'ProgramVersion', 75 => 'ObjectCycle', 80 => 'By-line', 85 => 'By-lineTitle',
  116. 90 => 'City', 92 => 'Sub-location', 95 => 'Province-State',
  117. 100 => 'Country-PrimaryLocationCode', 101 => 'Country-PrimaryLocationName',
  118. 103 => 'OriginalTransmissionReference', 105 => 'Headline', 110 => 'Credit', 115 => 'Source',
  119. 116 => 'CopyrightNotice', 118 => 'Contact', 120 => 'Caption-Abstract', 121 => 'LocalCaption',
  120. 122 => 'Writer-Editor', 125 => 'RasterizedCaption', 130 => 'ImageType',
  121. 131 => 'ImageOrientation', 135 => 'LanguageIdentifier', 150 => 'AudioType',
  122. 151 => 'AudioSamplingRate', 152 => 'AudioSamplingResolution', 153 => 'AudioDuration',
  123. 154 => 'AudioOutcue', 184 => 'JobID', 185 => 'MasterDocumentID', 186 => 'ShortDocumentID',
  124. 187 => 'UniqueDocumentID', 188 => 'OwnerID', 200 => 'ObjectPreviewFileFormat',
  125. 201 => 'ObjectPreviewFileVersion', 202 => 'ObjectPreviewData', 221 => 'Prefs',
  126. 225 => 'ClassifyState', 228 => 'SimilarityIndex', 230 => 'DocumentNotes',
  127. 231 => 'DocumentHistory', 232 => 'ExifCameraInfo'),
  128. 3 => array(// IPTC NewsPhoto Tags
  129. 0 => 'NewsPhotoVersion', 10 => 'IPTCPictureNumber', 20 => 'IPTCImageWidth',
  130. 30 => 'IPTCImageHeight', 40 => 'IPTCPixelWidth', 50 => 'IPTCPixelHeight',
  131. 55 => 'SupplementalType', 60 => 'ColorRepresentation', 64 => 'InterchangeColorSpace',
  132. 65 => 'ColorSequence', 66 => 'ICC_Profile', 70 => 'ColorCalibrationMatrix',
  133. 80 => 'LookupTable', 84 => 'NumIndexEntries', 85 => 'ColorPalette',
  134. 86 => 'IPTCBitsPerSample', 90 => 'SampleStructure', 100 => 'ScanningDirection',
  135. 102 => 'IPTCImageRotation', 110 => 'DataCompressionMethod', 120 => 'QuantizationMethod',
  136. 125 => 'EndPoints', 130 => 'ExcursionTolerance', 135 => 'BitsPerComponent',
  137. 140 => 'MaximumDensityRange', 145 => 'GammaCompensatedValue'),
  138. 7 => array(// IPTC PreObjectData Tags
  139. 10 => 'SizeMode', 20 => 'MaxSubfileSize', 90 => 'ObjectSizeAnnounced',
  140. 95 => 'MaximumObjectSize'), 8 => array(// IPTC ObjectData Tags
  141. 10 => 'SubFile'),
  142. 9 => array(// IPTC PostObjectData Tags
  143. 10 => 'ConfirmedObjectSize'));
  144. }
  145. return (isset($IPTCrecordTagName[$iptc_record][$iptc_tagkey]) ? $IPTCrecordTagName[$iptc_record][$iptc_tagkey] : $iptc_tagkey);
  146. }
  147. }
  148. ?>