57d500f55b97eb29757e532830097e18f7725cf7
3 /////////////////////////////////////////////////////////////////
4 /// getID3() by James Heinrich <info@getid3.org> //
5 // available at https://github.com/JamesHeinrich/getID3 //
6 // or https://www.getid3.org //
7 // or http://getid3.sourceforge.net //
8 // see readme.txt for more details //
9 /////////////////////////////////////////////////////////////////
11 // module.archive.tiff.php //
12 // module for analyzing TIFF files //
13 // dependencies: NONE //
15 /////////////////////////////////////////////////////////////////
18 class getid3_tiff
extends getid3_handler
23 public function Analyze() {
24 $info = &$this->getid3
->info
;
26 $this->fseek($info['avdataoffset']);
27 $TIFFheader = $this->fread(4);
29 switch (substr($TIFFheader, 0, 2)) {
31 $info['tiff']['byte_order'] = 'Intel';
34 $info['tiff']['byte_order'] = 'Motorola';
37 $this->error('Invalid TIFF byte order identifier ('.substr($TIFFheader, 0, 2).') at offset '.$info['avdataoffset']);
42 $info['fileformat'] = 'tiff';
43 $info['video']['dataformat'] = 'tiff';
44 $info['video']['lossless'] = true;
45 $info['tiff']['ifd'] = array();
46 $CurrentIFD = array();
48 $FieldTypeByteLength = array(1=>1, 2=>1, 3=>2, 4=>4, 5=>8);
50 $nextIFDoffset = $this->TIFFendian2Int($this->fread(4), $info['tiff']['byte_order']);
52 while ($nextIFDoffset > 0) {
54 $CurrentIFD['offset'] = $nextIFDoffset;
56 $this->fseek($info['avdataoffset'] +
$nextIFDoffset);
57 $CurrentIFD['fieldcount'] = $this->TIFFendian2Int($this->fread(2), $info['tiff']['byte_order']);
59 for ($i = 0; $i < $CurrentIFD['fieldcount']; $i++
) {
60 $CurrentIFD['fields'][$i]['raw']['tag'] = $this->TIFFendian2Int($this->fread(2), $info['tiff']['byte_order']);
61 $CurrentIFD['fields'][$i]['raw']['type'] = $this->TIFFendian2Int($this->fread(2), $info['tiff']['byte_order']);
62 $CurrentIFD['fields'][$i]['raw']['length'] = $this->TIFFendian2Int($this->fread(4), $info['tiff']['byte_order']);
63 $CurrentIFD['fields'][$i]['raw']['offset'] = $this->fread(4);
65 $CurrentIFD['fields'][$i]['raw']['tag_name'] = $this->TIFFcommentName($CurrentIFD['fields'][$i]['raw']['tag']);
67 switch ($CurrentIFD['fields'][$i]['raw']['type']) {
68 case 1: // BYTE An 8-bit unsigned integer.
69 if ($CurrentIFD['fields'][$i]['raw']['length'] <= 4) {
70 $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int(substr($CurrentIFD['fields'][$i]['raw']['offset'], 0, 1), $info['tiff']['byte_order']);
72 $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']);
76 case 2: // ASCII 8-bit bytes that store ASCII codes; the last byte must be null.
77 if ($CurrentIFD['fields'][$i]['raw']['length'] <= 4) {
78 $CurrentIFD['fields'][$i]['value'] = substr($CurrentIFD['fields'][$i]['raw']['offset'], 3);
80 $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']);
84 case 3: // SHORT A 16-bit (2-byte) unsigned integer.
85 if ($CurrentIFD['fields'][$i]['raw']['length'] <= 2) {
86 $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int(substr($CurrentIFD['fields'][$i]['raw']['offset'], 0, 2), $info['tiff']['byte_order']);
88 $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']);
92 case 4: // LONG A 32-bit (4-byte) unsigned integer.
93 if ($CurrentIFD['fields'][$i]['raw']['length'] <= 1) {
94 $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']);
96 $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']);
100 case 5: // RATIONAL Two LONG_s: the first represents the numerator of a fraction, the second the denominator.
105 $info['tiff']['ifd'][] = $CurrentIFD;
106 $CurrentIFD = array();
107 $nextIFDoffset = $this->TIFFendian2Int($this->fread(4), $info['tiff']['byte_order']);
111 foreach ($info['tiff']['ifd'] as $IFDid => $IFDarray) {
112 foreach ($IFDarray['fields'] as $key => $fieldarray) {
113 switch ($fieldarray['raw']['tag']) {
114 case 256: // ImageWidth
115 case 257: // ImageLength
116 case 258: // BitsPerSample
117 case 259: // Compression
118 if (!isset($fieldarray['value'])) {
119 $this->fseek($fieldarray['offset']);
120 $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $this->fread($fieldarray['raw']['length'] * $FieldTypeByteLength[$fieldarray['raw']['type']]);
125 case 270: // ImageDescription
128 case 305: // Software
129 case 306: // DateTime
131 case 316: // HostComputer
132 if (isset($fieldarray['value'])) {
133 $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $fieldarray['value'];
135 $this->fseek($fieldarray['offset']);
136 $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $this->fread($fieldarray['raw']['length'] * $FieldTypeByteLength[$fieldarray['raw']['type']]);
141 switch ($fieldarray['raw']['tag']) {
142 case 256: // ImageWidth
143 $info['video']['resolution_x'] = $fieldarray['value'];
146 case 257: // ImageLength
147 $info['video']['resolution_y'] = $fieldarray['value'];
150 case 258: // BitsPerSample
151 if (isset($fieldarray['value'])) {
152 $info['video']['bits_per_sample'] = $fieldarray['value'];
154 $info['video']['bits_per_sample'] = 0;
155 for ($i = 0; $i < $fieldarray['raw']['length']; $i++
) {
156 $info['video']['bits_per_sample'] +
= $this->TIFFendian2Int(substr($info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'], $i * $FieldTypeByteLength[$fieldarray['raw']['type']], $FieldTypeByteLength[$fieldarray['raw']['type']]), $info['tiff']['byte_order']);
161 case 259: // Compression
162 $info['video']['codec'] = $this->TIFFcompressionMethod($fieldarray['value']);
165 case 270: // ImageDescription
168 case 305: // Software
169 case 306: // DateTime
171 case 316: // HostComputer
172 $TIFFcommentName = strtolower($fieldarray['raw']['tag_name']);
173 if (isset($info['tiff']['comments'][$TIFFcommentName])) {
174 $info['tiff']['comments'][$TIFFcommentName][] = $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'];
176 $info['tiff']['comments'][$TIFFcommentName] = array($info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data']);
190 * @param string $bytestring
191 * @param string $byteorder
193 * @return int|float|false
195 public function TIFFendian2Int($bytestring, $byteorder) {
196 if ($byteorder == 'Intel') {
197 return getid3_lib
::LittleEndian2Int($bytestring);
198 } elseif ($byteorder == 'Motorola') {
199 return getid3_lib
::BigEndian2Int($bytestring);
209 public function TIFFcompressionMethod($id) {
210 static $TIFFcompressionMethod = array();
211 if (empty($TIFFcompressionMethod)) {
212 $TIFFcompressionMethod = array(
215 3 => 'Fax - CCITT 3',
220 return (isset($TIFFcompressionMethod[$id]) ?
$TIFFcompressionMethod[$id] : 'unknown/invalid ('.$id.')');
228 public function TIFFcommentName($id) {
229 // https://www.awaresystems.be/imaging/tiff/tifftags.html
230 static $TIFFcommentName = array();
231 if (empty($TIFFcommentName)) {
232 $TIFFcommentName = array(
233 254 => 'NewSubfileType',
234 255 => 'SubfileType',
236 257 => 'ImageLength',
237 258 => 'BitsPerSample',
238 259 => 'Compression',
239 262 => 'PhotometricInterpretation',
240 263 => 'Threshholding',
244 269 => 'DocumentName',
245 270 => 'ImageDescription',
248 273 => 'StripOffsets',
249 274 => 'Orientation',
250 277 => 'SamplesPerPixel',
251 278 => 'RowsPerStrip',
252 279 => 'StripByteCounts',
253 280 => 'MinSampleValue',
254 281 => 'MaxSampleValue',
255 282 => 'XResolution',
256 283 => 'YResolution',
257 284 => 'PlanarConfiguration',
261 288 => 'FreeOffsets',
262 289 => 'FreeByteCounts',
263 290 => 'GrayResponseUnit',
264 291 => 'GrayResponseCurve',
267 296 => 'ResolutionUnit',
269 301 => 'TransferFunction',
273 316 => 'HostComputer',
276 319 => 'PrimaryChromaticities',
278 321 => 'HalftoneHints',
281 324 => 'TileOffsets',
282 325 => 'TileByteCounts',
283 326 => 'BadFaxLines',
284 327 => 'CleanFaxData',
285 328 => 'ConsecutiveBadFaxLines',
289 334 => 'NumberOfInks',
291 337 => 'TargetPrinter',
292 338 => 'ExtraSamples',
293 339 => 'SampleFormat',
294 340 => 'SMinSampleValue',
295 341 => 'SMaxSampleValue',
296 342 => 'TransferRange',
298 344 => 'XClipPathUnits',
299 345 => 'YClipPathUnits',
303 400 => 'GlobalParametersIFD',
304 401 => 'ProfileType',
306 403 => 'CodingMethods',
307 404 => 'VersionYear',
310 434 => 'DefaultImageColor',
312 513 => 'JPEGInterchangeFormat',
313 514 => 'JPEGInterchangeFormatLngth',
314 515 => 'JPEGRestartInterval',
315 517 => 'JPEGLosslessPredictors',
316 518 => 'JPEGPointTransforms',
317 519 => 'JPEGQTables',
318 520 => 'JPEGDCTables',
319 521 => 'JPEGACTables',
320 529 => 'YCbCrCoefficients',
321 530 => 'YCbCrSubSampling',
322 531 => 'YCbCrPositioning',
323 532 => 'ReferenceBlackWhite',
324 559 => 'StripRowCounts',
328 33432 => 'Copyright',
329 34732 => 'ImageLayer',
331 // Private Tags - https://www.awaresystems.be/imaging/tiff/tifftags/private.html
332 32932 => 'Wang Annotation', // Annotation data, as used in 'Imaging for Windows'.
333 33445 => 'MD FileTag', // Specifies the pixel data format encoding in the Molecular Dynamics GEL file format.
334 33446 => 'MD ScalePixel', // Specifies a scale factor in the Molecular Dynamics GEL file format.
335 33447 => 'MD ColorTable', // Used to specify the conversion from 16bit to 8bit in the Molecular Dynamics GEL file format.
336 33448 => 'MD LabName', // Name of the lab that scanned this file, as used in the Molecular Dynamics GEL file format.
337 33449 => 'MD SampleInfo', // Information about the sample, as used in the Molecular Dynamics GEL file format.
338 33450 => 'MD PrepDate', // Date the sample was prepared, as used in the Molecular Dynamics GEL file format.
339 33451 => 'MD PrepTime', // Time the sample was prepared, as used in the Molecular Dynamics GEL file format.
340 33452 => 'MD FileUnits', // Units for data in this file, as used in the Molecular Dynamics GEL file format.
341 33550 => 'ModelPixelScaleTag', // Used in interchangeable GeoTIFF files.
342 33723 => 'IPTC', // IPTC (International Press Telecommunications Council) metadata.
343 33918 => 'INGR Packet Data Tag', // Intergraph Application specific storage.
344 33919 => 'INGR Flag Registers', // Intergraph Application specific flags.
345 33920 => 'IrasB Transformation Matrix', // Originally part of Intergraph's GeoTIFF tags, but likely understood by IrasB only.
346 33922 => 'ModelTiepointTag', // Originally part of Intergraph's GeoTIFF tags, but now used in interchangeable GeoTIFF files.
347 34264 => 'ModelTransformationTag', // Used in interchangeable GeoTIFF files.
348 34377 => 'Photoshop', // Collection of Photoshop 'Image Resource Blocks'.
349 34665 => 'Exif IFD', // A pointer to the Exif IFD.
350 34675 => 'ICC Profile', // ICC profile data.
351 34735 => 'GeoKeyDirectoryTag', // Used in interchangeable GeoTIFF files.
352 34736 => 'GeoDoubleParamsTag', // Used in interchangeable GeoTIFF files.
353 34737 => 'GeoAsciiParamsTag', // Used in interchangeable GeoTIFF files.
354 34853 => 'GPS IFD', // A pointer to the Exif-related GPS Info IFD.
355 34908 => 'HylaFAX FaxRecvParams', // Used by HylaFAX.
356 34909 => 'HylaFAX FaxSubAddress', // Used by HylaFAX.
357 34910 => 'HylaFAX FaxRecvTime', // Used by HylaFAX.
358 37724 => 'ImageSourceData', // Used by Adobe Photoshop.
359 40965 => 'Interoperability IFD', // A pointer to the Exif-related Interoperability IFD.
360 42112 => 'GDAL_METADATA', // Used by the GDAL library, holds an XML list of name=value 'metadata' values about the image as a whole, and about specific samples.
361 42113 => 'GDAL_NODATA', // Used by the GDAL library, contains an ASCII encoded nodata or background pixel value.
362 50215 => 'Oce Scanjob Description', // Used in the Oce scanning process.
363 50216 => 'Oce Application Selector', // Used in the Oce scanning process.
364 50217 => 'Oce Identification Number', // Used in the Oce scanning process.
365 50218 => 'Oce ImageLogic Characteristics', // Used in the Oce scanning process.
366 50706 => 'DNGVersion', // Used in IFD 0 of DNG files.
367 50707 => 'DNGBackwardVersion', // Used in IFD 0 of DNG files.
368 50708 => 'UniqueCameraModel', // Used in IFD 0 of DNG files.
369 50709 => 'LocalizedCameraModel', // Used in IFD 0 of DNG files.
370 50710 => 'CFAPlaneColor', // Used in Raw IFD of DNG files.
371 50711 => 'CFALayout', // Used in Raw IFD of DNG files.
372 50712 => 'LinearizationTable', // Used in Raw IFD of DNG files.
373 50713 => 'BlackLevelRepeatDim', // Used in Raw IFD of DNG files.
374 50714 => 'BlackLevel', // Used in Raw IFD of DNG files.
375 50715 => 'BlackLevelDeltaH', // Used in Raw IFD of DNG files.
376 50716 => 'BlackLevelDeltaV', // Used in Raw IFD of DNG files.
377 50717 => 'WhiteLevel', // Used in Raw IFD of DNG files.
378 50718 => 'DefaultScale', // Used in Raw IFD of DNG files.
379 50719 => 'DefaultCropOrigin', // Used in Raw IFD of DNG files.
380 50720 => 'DefaultCropSize', // Used in Raw IFD of DNG files.
381 50721 => 'ColorMatrix1', // Used in IFD 0 of DNG files.
382 50722 => 'ColorMatrix2', // Used in IFD 0 of DNG files.
383 50723 => 'CameraCalibration1', // Used in IFD 0 of DNG files.
384 50724 => 'CameraCalibration2', // Used in IFD 0 of DNG files.
385 50725 => 'ReductionMatrix1', // Used in IFD 0 of DNG files.
386 50726 => 'ReductionMatrix2', // Used in IFD 0 of DNG files.
387 50727 => 'AnalogBalance', // Used in IFD 0 of DNG files.
388 50728 => 'AsShotNeutral', // Used in IFD 0 of DNG files.
389 50729 => 'AsShotWhiteXY', // Used in IFD 0 of DNG files.
390 50730 => 'BaselineExposure', // Used in IFD 0 of DNG files.
391 50731 => 'BaselineNoise', // Used in IFD 0 of DNG files.
392 50732 => 'BaselineSharpness', // Used in IFD 0 of DNG files.
393 50733 => 'BayerGreenSplit', // Used in Raw IFD of DNG files.
394 50734 => 'LinearResponseLimit', // Used in IFD 0 of DNG files.
395 50735 => 'CameraSerialNumber', // Used in IFD 0 of DNG files.
396 50736 => 'LensInfo', // Used in IFD 0 of DNG files.
397 50737 => 'ChromaBlurRadius', // Used in Raw IFD of DNG files.
398 50738 => 'AntiAliasStrength', // Used in Raw IFD of DNG files.
399 50740 => 'DNGPrivateData', // Used in IFD 0 of DNG files.
400 50741 => 'MakerNoteSafety', // Used in IFD 0 of DNG files.
401 50778 => 'CalibrationIlluminant1', // Used in IFD 0 of DNG files.
402 50779 => 'CalibrationIlluminant2', // Used in IFD 0 of DNG files.
403 50780 => 'BestQualityScale', // Used in Raw IFD of DNG files.
404 50784 => 'Alias Layer Metadata', // Alias Sketchbook Pro layer usage description.
405 50908 => 'TIFF_RSID', // This private tag is used in a GEOTIFF standard by DGIWG.
406 50909 => 'GEO_METADATA', // This private tag is used in a GEOTIFF standard by DGIWG.
408 // EXIF tags - https://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif.html
409 33434 => 'ExposureTime', // Exposure time, given in seconds.
410 33437 => 'FNumber', // The F number.
411 34850 => 'ExposureProgram', // The class of the program used by the camera to set exposure when the picture is taken.
412 34852 => 'SpectralSensitivity', // Indicates the spectral sensitivity of each channel of the camera used.
413 34855 => 'ISOSpeedRatings', // Indicates the ISO Speed and ISO Latitude of the camera or input device as specified in ISO 12232.
414 34856 => 'OECF', // Indicates the Opto-Electric Conversion Function (OECF) specified in ISO 14524.
415 36864 => 'ExifVersion', // The version of the supported Exif standard.
416 36867 => 'DateTimeOriginal', // The date and time when the original image data was generated.
417 36868 => 'DateTimeDigitized', // The date and time when the image was stored as digital data.
418 37121 => 'ComponentsConfiguration', // Specific to compressed data; specifies the channels and complements PhotometricInterpretation
419 37122 => 'CompressedBitsPerPixel', // Specific to compressed data; states the compressed bits per pixel.
420 37377 => 'ShutterSpeedValue', // Shutter speed.
421 37378 => 'ApertureValue', // The lens aperture.
422 37379 => 'BrightnessValue', // The value of brightness.
423 37380 => 'ExposureBiasValue', // The exposure bias.
424 37381 => 'MaxApertureValue', // The smallest F number of the lens.
425 37382 => 'SubjectDistance', // The distance to the subject, given in meters.
426 37383 => 'MeteringMode', // The metering mode.
427 37384 => 'LightSource', // The kind of light source.
428 37385 => 'Flash', // Indicates the status of flash when the image was shot.
429 37386 => 'FocalLength', // The actual focal length of the lens, in mm.
430 37396 => 'SubjectArea', // Indicates the location and area of the main subject in the overall scene.
431 37500 => 'MakerNote', // Manufacturer specific information.
432 37510 => 'UserComment', // Keywords or comments on the image; complements ImageDescription.
433 37520 => 'SubsecTime', // A tag used to record fractions of seconds for the DateTime tag.
434 37521 => 'SubsecTimeOriginal', // A tag used to record fractions of seconds for the DateTimeOriginal tag.
435 37522 => 'SubsecTimeDigitized', // A tag used to record fractions of seconds for the DateTimeDigitized tag.
436 40960 => 'FlashpixVersion', // The Flashpix format version supported by a FPXR file.
437 40961 => 'ColorSpace', // The color space information tag is always recorded as the color space specifier.
438 40962 => 'PixelXDimension', // Specific to compressed data; the valid width of the meaningful image.
439 40963 => 'PixelYDimension', // Specific to compressed data; the valid height of the meaningful image.
440 40964 => 'RelatedSoundFile', // Used to record the name of an audio file related to the image data.
441 41483 => 'FlashEnergy', // Indicates the strobe energy at the time the image is captured, as measured in Beam Candle Power Seconds
442 41484 => 'SpatialFrequencyResponse', // Records the camera or input device spatial frequency table and SFR values in the direction of image width, image height, and diagonal direction, as specified in ISO 12233.
443 41486 => 'FocalPlaneXResolution', // Indicates the number of pixels in the image width (X) direction per FocalPlaneResolutionUnit on the camera focal plane.
444 41487 => 'FocalPlaneYResolution', // Indicates the number of pixels in the image height (Y) direction per FocalPlaneResolutionUnit on the camera focal plane.
445 41488 => 'FocalPlaneResolutionUnit', // Indicates the unit for measuring FocalPlaneXResolution and FocalPlaneYResolution.
446 41492 => 'SubjectLocation', // Indicates the location of the main subject in the scene.
447 41493 => 'ExposureIndex', // Indicates the exposure index selected on the camera or input device at the time the image is captured.
448 41495 => 'SensingMethod', // Indicates the image sensor type on the camera or input device.
449 41728 => 'FileSource', // Indicates the image source.
450 41729 => 'SceneType', // Indicates the type of scene.
451 41730 => 'CFAPattern', // Indicates the color filter array (CFA) geometric pattern of the image sensor when a one-chip color area sensor is used.
452 41985 => 'CustomRendered', // Indicates the use of special processing on image data, such as rendering geared to output.
453 41986 => 'ExposureMode', // Indicates the exposure mode set when the image was shot.
454 41987 => 'WhiteBalance', // Indicates the white balance mode set when the image was shot.
455 41988 => 'DigitalZoomRatio', // Indicates the digital zoom ratio when the image was shot.
456 41989 => 'FocalLengthIn35mmFilm', // Indicates the equivalent focal length assuming a 35mm film camera, in mm.
457 41990 => 'SceneCaptureType', // Indicates the type of scene that was shot.
458 41991 => 'GainControl', // Indicates the degree of overall image gain adjustment.
459 41992 => 'Contrast', // Indicates the direction of contrast processing applied by the camera when the image was shot.
460 41993 => 'Saturation', // Indicates the direction of saturation processing applied by the camera when the image was shot.
461 41994 => 'Sharpness', // Indicates the direction of sharpness processing applied by the camera when the image was shot.
462 41995 => 'DeviceSettingDescription', // This tag indicates information on the picture-taking conditions of a particular camera model.
463 41996 => 'SubjectDistanceRange', // Indicates the distance to the subject.
464 42016 => 'ImageUniqueID', // Indicates an identifier assigned uniquely to each image.
467 return (isset($TIFFcommentName[$id]) ?
$TIFFcommentName[$id] : 'unknown/invalid ('.$id.')');