ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
getid3_jpg Class Reference

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g // More...

+ Inheritance diagram for getid3_jpg:
+ Collaboration diagram for getid3_jpg:

Public Member Functions

 getid3_jpg (&$fd, &$ThisFileInfo)
 
 Analyze ()
 
 CastAsAppropriate ($value)
 
 IPTCrecordName ($iptc_record)
 
 IPTCrecordTagName ($iptc_record, $iptc_tagkey)
 
- Public Member Functions inherited from getid3_handler
 __construct (getID3 $getid3, $call_module=null)
 
 Analyze ()
 
 AnalyzeString ($string)
 
 setStringMode ($string)
 
 saveAttachment ($name, $offset, $length, $image_mime=null)
 

Additional Inherited Members

- Protected Member Functions inherited from getid3_handler
 ftell ()
 
 fread ($bytes)
 
 fseek ($bytes, $whence=SEEK_SET)
 
 feof ()
 
 isDependencyFor ($module)
 
 error ($text)
 
 warning ($text)
 
 notice ($text)
 
- Protected Attributes inherited from getid3_handler
 $getid3
 
 $data_string_flag = false
 
 $data_string = ''
 
 $data_string_position = 0
 
 $data_string_length = 0
 

Detailed Description

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //

Definition at line 17 of file module.graphic.jpg.php.

Member Function Documentation

◆ Analyze()

getid3_jpg::Analyze ( )

Reimplemented from getid3_handler.

Definition at line 23 of file module.graphic.jpg.php.

23 {
24 $info = &$this->getid3->info;
25
26 $info['fileformat'] = 'jpg';
27 $info['video']['dataformat'] = 'jpg';
28 $info['video']['lossless'] = false;
29 $info['video']['bits_per_sample'] = 24;
30 $info['video']['pixel_aspect_ratio'] = (float) 1;
31
32 $this->fseek($info['avdataoffset']);
33
34 $imageinfo = array();
35 //list($width, $height, $type) = getid3_lib::GetDataImageSize($this->fread($info['filesize']), $imageinfo);
36 list($width, $height, $type) = getimagesize($info['filenamepath'], $imageinfo); // http://www.getid3.org/phpBB3/viewtopic.php?t=1474
37
38
39 if (isset($imageinfo['APP13'])) {
40 // http://php.net/iptcparse
41 // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html
42 $iptc_parsed = iptcparse($imageinfo['APP13']);
43 if (is_array($iptc_parsed)) {
44 foreach ($iptc_parsed as $iptc_key_raw => $iptc_values) {
45 list($iptc_record, $iptc_tagkey) = explode('#', $iptc_key_raw);
46 $iptc_tagkey = intval(ltrim($iptc_tagkey, '0'));
47 foreach ($iptc_values as $key => $value) {
48 $IPTCrecordName = $this->IPTCrecordName($iptc_record);
49 $IPTCrecordTagName = $this->IPTCrecordTagName($iptc_record, $iptc_tagkey);
50 if (isset($info['iptc']['comments'][$IPTCrecordName][$IPTCrecordTagName])) {
51 $info['iptc']['comments'][$IPTCrecordName][$IPTCrecordTagName][] = $value;
52 } else {
53 $info['iptc']['comments'][$IPTCrecordName][$IPTCrecordTagName] = array($value);
54 }
55 }
56 }
57 }
58 }
59
60 $returnOK = false;
61 switch ($type) {
62 case IMG_JPG:
63 $info['video']['resolution_x'] = $width;
64 $info['video']['resolution_y'] = $height;
65
66 if (isset($imageinfo['APP1'])) {
67 if (function_exists('exif_read_data')) {
68 if (substr($imageinfo['APP1'], 0, 4) == 'Exif') {
69//$info['warning'][] = 'known issue: https://bugs.php.net/bug.php?id=62523';
70//return false;
71 $info['jpg']['exif'] = exif_read_data($info['filenamepath'], null, true, false);
72 } else {
73 $info['warning'][] = 'exif_read_data() cannot parse non-EXIF data in APP1 (expected "Exif", found "'.substr($imageinfo['APP1'], 0, 4).'")';
74 }
75 } else {
76 $info['warning'][] = 'EXIF parsing only available when '.(GETID3_OS_ISWINDOWS ? 'php_exif.dll enabled' : 'compiled with --enable-exif');
77 }
78 }
79 $returnOK = true;
80 break;
81
82 default:
83 break;
84 }
85
86
87 $cast_as_appropriate_keys = array('EXIF', 'IFD0', 'THUMBNAIL');
88 foreach ($cast_as_appropriate_keys as $exif_key) {
89 if (isset($info['jpg']['exif'][$exif_key])) {
90 foreach ($info['jpg']['exif'][$exif_key] as $key => $value) {
91 $info['jpg']['exif'][$exif_key][$key] = $this->CastAsAppropriate($value);
92 }
93 }
94 }
95
96
97 if (isset($info['jpg']['exif']['GPS'])) {
98
99 if (isset($info['jpg']['exif']['GPS']['GPSVersion'])) {
100 for ($i = 0; $i < 4; $i++) {
101 $version_subparts[$i] = ord(substr($info['jpg']['exif']['GPS']['GPSVersion'], $i, 1));
102 }
103 $info['jpg']['exif']['GPS']['computed']['version'] = 'v'.implode('.', $version_subparts);
104 }
105
106 if (isset($info['jpg']['exif']['GPS']['GPSDateStamp'])) {
107 $explodedGPSDateStamp = explode(':', $info['jpg']['exif']['GPS']['GPSDateStamp']);
108 $computed_time[5] = (isset($explodedGPSDateStamp[0]) ? $explodedGPSDateStamp[0] : '');
109 $computed_time[3] = (isset($explodedGPSDateStamp[1]) ? $explodedGPSDateStamp[1] : '');
110 $computed_time[4] = (isset($explodedGPSDateStamp[2]) ? $explodedGPSDateStamp[2] : '');
111
112 $computed_time = array(0=>0, 1=>0, 2=>0, 3=>0, 4=>0, 5=>0);
113 if (isset($info['jpg']['exif']['GPS']['GPSTimeStamp']) && is_array($info['jpg']['exif']['GPS']['GPSTimeStamp'])) {
114 foreach ($info['jpg']['exif']['GPS']['GPSTimeStamp'] as $key => $value) {
115 $computed_time[$key] = getid3_lib::DecimalizeFraction($value);
116 }
117 }
118 $info['jpg']['exif']['GPS']['computed']['timestamp'] = gmmktime($computed_time[0], $computed_time[1], $computed_time[2], $computed_time[3], $computed_time[4], $computed_time[5]);
119 }
120
121 if (isset($info['jpg']['exif']['GPS']['GPSLatitude']) && is_array($info['jpg']['exif']['GPS']['GPSLatitude'])) {
122 $direction_multiplier = ((isset($info['jpg']['exif']['GPS']['GPSLatitudeRef']) && ($info['jpg']['exif']['GPS']['GPSLatitudeRef'] == 'S')) ? -1 : 1);
123 foreach ($info['jpg']['exif']['GPS']['GPSLatitude'] as $key => $value) {
124 $computed_latitude[$key] = getid3_lib::DecimalizeFraction($value);
125 }
126 $info['jpg']['exif']['GPS']['computed']['latitude'] = $direction_multiplier * ($computed_latitude[0] + ($computed_latitude[1] / 60) + ($computed_latitude[2] / 3600));
127 }
128
129 if (isset($info['jpg']['exif']['GPS']['GPSLongitude']) && is_array($info['jpg']['exif']['GPS']['GPSLongitude'])) {
130 $direction_multiplier = ((isset($info['jpg']['exif']['GPS']['GPSLongitudeRef']) && ($info['jpg']['exif']['GPS']['GPSLongitudeRef'] == 'W')) ? -1 : 1);
131 foreach ($info['jpg']['exif']['GPS']['GPSLongitude'] as $key => $value) {
132 $computed_longitude[$key] = getid3_lib::DecimalizeFraction($value);
133 }
134 $info['jpg']['exif']['GPS']['computed']['longitude'] = $direction_multiplier * ($computed_longitude[0] + ($computed_longitude[1] / 60) + ($computed_longitude[2] / 3600));
135 }
136 if (isset($info['jpg']['exif']['GPS']['GPSAltitudeRef'])) {
137 $info['jpg']['exif']['GPS']['GPSAltitudeRef'] = ord($info['jpg']['exif']['GPS']['GPSAltitudeRef']); // 0 = above sea level; 1 = below sea level
138 }
139 if (isset($info['jpg']['exif']['GPS']['GPSAltitude'])) {
140 $direction_multiplier = (!empty($info['jpg']['exif']['GPS']['GPSAltitudeRef']) ? -1 : 1); // 0 = above sea level; 1 = below sea level
141 $info['jpg']['exif']['GPS']['computed']['altitude'] = $direction_multiplier * getid3_lib::DecimalizeFraction($info['jpg']['exif']['GPS']['GPSAltitude']);
142 }
143
144 }
145
146
147 getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.xmp.php', __FILE__, true);
148 if (isset($info['filenamepath'])) {
149 $image_xmp = new Image_XMP($info['filenamepath']);
150 $xmp_raw = $image_xmp->getAllTags();
151 foreach ($xmp_raw as $key => $value) {
152 if (strpos($key, ':')) {
153 list($subsection, $tagname) = explode(':', $key);
154 $info['xmp'][$subsection][$tagname] = $this->CastAsAppropriate($value);
155 } else {
156 $info['warning'][] = 'XMP: expecting "<subsection>:<tagname>", found "'.$key.'"';
157 }
158 }
159 }
160
161 if (!$returnOK) {
162 unset($info['fileformat']);
163 return false;
164 }
165 return true;
166 }
getID3() by James Heinrich info@getid3.org //
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
IPTCrecordName($iptc_record)
CastAsAppropriate($value)
IPTCrecordTagName($iptc_record, $iptc_tagkey)
static DecimalizeFraction($fraction)
Definition: getid3.lib.php:96
IncludeDependency($filename, $sourcefile, $DieOnFailure=false)
$info
Definition: example_052.php:80

References $info, CastAsAppropriate(), getid3_lib\DecimalizeFraction(), getid3_handler\fseek(), getid3_lib\IncludeDependency(), IPTCrecordName(), and IPTCrecordTagName().

+ Here is the call graph for this function:

◆ CastAsAppropriate()

getid3_jpg::CastAsAppropriate (   $value)

Definition at line 169 of file module.graphic.jpg.php.

169 {
170 if (is_array($value)) {
171 return $value;
172 } elseif (preg_match('#^[0-9]+/[0-9]+$#', $value)) {
173 return getid3_lib::DecimalizeFraction($value);
174 } elseif (preg_match('#^[0-9]+$#', $value)) {
175 return getid3_lib::CastAsInt($value);
176 } elseif (preg_match('#^[0-9\.]+$#', $value)) {
177 return (float) $value;
178 }
179 return $value;
180 }
CastAsInt($floatnum)
Definition: getid3.lib.php:60

References getid3_lib\CastAsInt(), and getid3_lib\DecimalizeFraction().

Referenced by Analyze().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getid3_jpg()

getid3_jpg::getid3_jpg ( $fd,
$ThisFileInfo 
)

Definition at line 21 of file module.graphic.jpg.php.

21 {
22 $ThisFileInfo['fileformat'] = 'jpg';
23 $ThisFileInfo['video']['dataformat'] = 'jpg';
24 $ThisFileInfo['video']['lossless'] = false;
25 $ThisFileInfo['video']['bits_per_sample'] = 24;
26 $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1;
27
28 fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
29
30 list($width, $height, $type) = getid3_lib::GetDataImageSize(fread($fd, $ThisFileInfo['filesize']));
31 if ($type == 2) {
32
33 $ThisFileInfo['video']['resolution_x'] = $width;
34 $ThisFileInfo['video']['resolution_y'] = $height;
35
36 if (version_compare(phpversion(), '4.2.0', '>=')) {
37
38 if (function_exists('exif_read_data')) {
39
40 ob_start();
41 $ThisFileInfo['jpg']['exif'] = exif_read_data($ThisFileInfo['filenamepath'], '', true, false);
42 $errors = ob_get_contents();
43 if ($errors) {
44 $ThisFileInfo['error'][] = strip_tags($errors);
45 unset($ThisFileInfo['jpg']['exif']);
46 }
47 ob_end_clean();
48
49 } else {
50
51 $ThisFileInfo['warning'][] = 'EXIF parsing only available when '.(GETID3_OS_ISWINDOWS ? 'php_exif.dll enabled' : 'compiled with --enable-exif');
52
53 }
54
55 } else {
56
57 $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();
58
59 }
60
61 return true;
62
63 }
64
65 unset($ThisFileInfo['fileformat']);
66 return false;
67 }
fread($bytes)
Definition: getid3.php:1685
GetDataImageSize($imgData)
$errors

References $errors, getid3_handler\fread(), getid3_handler\fseek(), and getid3_lib\GetDataImageSize().

+ Here is the call graph for this function:

◆ IPTCrecordName()

getid3_jpg::IPTCrecordName (   $iptc_record)

Definition at line 183 of file module.graphic.jpg.php.

183 {
184 // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html
185 static $IPTCrecordName = array();
186 if (empty($IPTCrecordName)) {
187 $IPTCrecordName = array(
188 1 => 'IPTCEnvelope',
189 2 => 'IPTCApplication',
190 3 => 'IPTCNewsPhoto',
191 7 => 'IPTCPreObjectData',
192 8 => 'IPTCObjectData',
193 9 => 'IPTCPostObjectData',
194 );
195 }
196 return (isset($IPTCrecordName[$iptc_record]) ? $IPTCrecordName[$iptc_record] : '');
197 }

Referenced by Analyze().

+ Here is the caller graph for this function:

◆ IPTCrecordTagName()

getid3_jpg::IPTCrecordTagName (   $iptc_record,
  $iptc_tagkey 
)

Definition at line 200 of file module.graphic.jpg.php.

200 {
201 // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html
202 static $IPTCrecordTagName = array();
203 if (empty($IPTCrecordTagName)) {
204 $IPTCrecordTagName = array(
205 1 => array( // IPTC EnvelopeRecord Tags
206 0 => 'EnvelopeRecordVersion',
207 5 => 'Destination',
208 20 => 'FileFormat',
209 22 => 'FileVersion',
210 30 => 'ServiceIdentifier',
211 40 => 'EnvelopeNumber',
212 50 => 'ProductID',
213 60 => 'EnvelopePriority',
214 70 => 'DateSent',
215 80 => 'TimeSent',
216 90 => 'CodedCharacterSet',
217 100 => 'UniqueObjectName',
218 120 => 'ARMIdentifier',
219 122 => 'ARMVersion',
220 ),
221 2 => array( // IPTC ApplicationRecord Tags
222 0 => 'ApplicationRecordVersion',
223 3 => 'ObjectTypeReference',
224 4 => 'ObjectAttributeReference',
225 5 => 'ObjectName',
226 7 => 'EditStatus',
227 8 => 'EditorialUpdate',
228 10 => 'Urgency',
229 12 => 'SubjectReference',
230 15 => 'Category',
231 20 => 'SupplementalCategories',
232 22 => 'FixtureIdentifier',
233 25 => 'Keywords',
234 26 => 'ContentLocationCode',
235 27 => 'ContentLocationName',
236 30 => 'ReleaseDate',
237 35 => 'ReleaseTime',
238 37 => 'ExpirationDate',
239 38 => 'ExpirationTime',
240 40 => 'SpecialInstructions',
241 42 => 'ActionAdvised',
242 45 => 'ReferenceService',
243 47 => 'ReferenceDate',
244 50 => 'ReferenceNumber',
245 55 => 'DateCreated',
246 60 => 'TimeCreated',
247 62 => 'DigitalCreationDate',
248 63 => 'DigitalCreationTime',
249 65 => 'OriginatingProgram',
250 70 => 'ProgramVersion',
251 75 => 'ObjectCycle',
252 80 => 'By-line',
253 85 => 'By-lineTitle',
254 90 => 'City',
255 92 => 'Sub-location',
256 95 => 'Province-State',
257 100 => 'Country-PrimaryLocationCode',
258 101 => 'Country-PrimaryLocationName',
259 103 => 'OriginalTransmissionReference',
260 105 => 'Headline',
261 110 => 'Credit',
262 115 => 'Source',
263 116 => 'CopyrightNotice',
264 118 => 'Contact',
265 120 => 'Caption-Abstract',
266 121 => 'LocalCaption',
267 122 => 'Writer-Editor',
268 125 => 'RasterizedCaption',
269 130 => 'ImageType',
270 131 => 'ImageOrientation',
271 135 => 'LanguageIdentifier',
272 150 => 'AudioType',
273 151 => 'AudioSamplingRate',
274 152 => 'AudioSamplingResolution',
275 153 => 'AudioDuration',
276 154 => 'AudioOutcue',
277 184 => 'JobID',
278 185 => 'MasterDocumentID',
279 186 => 'ShortDocumentID',
280 187 => 'UniqueDocumentID',
281 188 => 'OwnerID',
282 200 => 'ObjectPreviewFileFormat',
283 201 => 'ObjectPreviewFileVersion',
284 202 => 'ObjectPreviewData',
285 221 => 'Prefs',
286 225 => 'ClassifyState',
287 228 => 'SimilarityIndex',
288 230 => 'DocumentNotes',
289 231 => 'DocumentHistory',
290 232 => 'ExifCameraInfo',
291 ),
292 3 => array( // IPTC NewsPhoto Tags
293 0 => 'NewsPhotoVersion',
294 10 => 'IPTCPictureNumber',
295 20 => 'IPTCImageWidth',
296 30 => 'IPTCImageHeight',
297 40 => 'IPTCPixelWidth',
298 50 => 'IPTCPixelHeight',
299 55 => 'SupplementalType',
300 60 => 'ColorRepresentation',
301 64 => 'InterchangeColorSpace',
302 65 => 'ColorSequence',
303 66 => 'ICC_Profile',
304 70 => 'ColorCalibrationMatrix',
305 80 => 'LookupTable',
306 84 => 'NumIndexEntries',
307 85 => 'ColorPalette',
308 86 => 'IPTCBitsPerSample',
309 90 => 'SampleStructure',
310 100 => 'ScanningDirection',
311 102 => 'IPTCImageRotation',
312 110 => 'DataCompressionMethod',
313 120 => 'QuantizationMethod',
314 125 => 'EndPoints',
315 130 => 'ExcursionTolerance',
316 135 => 'BitsPerComponent',
317 140 => 'MaximumDensityRange',
318 145 => 'GammaCompensatedValue',
319 ),
320 7 => array( // IPTC PreObjectData Tags
321 10 => 'SizeMode',
322 20 => 'MaxSubfileSize',
323 90 => 'ObjectSizeAnnounced',
324 95 => 'MaximumObjectSize',
325 ),
326 8 => array( // IPTC ObjectData Tags
327 10 => 'SubFile',
328 ),
329 9 => array( // IPTC PostObjectData Tags
330 10 => 'ConfirmedObjectSize',
331 ),
332 );
333
334 }
335 return (isset($IPTCrecordTagName[$iptc_record][$iptc_tagkey]) ? $IPTCrecordTagName[$iptc_record][$iptc_tagkey] : $iptc_tagkey);
336 }

Referenced by Analyze().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: