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

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

+ Inheritance diagram for getid3_tiff:
+ Collaboration diagram for getid3_tiff:

Public Member Functions

 getid3_tiff (&$fd, &$ThisFileInfo)
 
 TIFFendian2Int ($bytestring, $byteorder)
 
 TIFFcompressionMethod ($id)
 
 TIFFcommentName ($id)
 
 Analyze ()
 
 TIFFendian2Int ($bytestring, $byteorder)
 
 TIFFcompressionMethod ($id)
 
 TIFFcommentName ($id)
 
- 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.tiff.php.

Member Function Documentation

◆ Analyze()

getid3_tiff::Analyze ( )

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

References $info, getid3_handler\fread(), getid3_handler\fseek(), TIFFcommentName(), TIFFcompressionMethod(), and TIFFendian2Int().

21  {
22  $info = &$this->getid3->info;
23 
24  $this->fseek($info['avdataoffset']);
25  $TIFFheader = $this->fread(4);
26 
27  switch (substr($TIFFheader, 0, 2)) {
28  case 'II':
29  $info['tiff']['byte_order'] = 'Intel';
30  break;
31  case 'MM':
32  $info['tiff']['byte_order'] = 'Motorola';
33  break;
34  default:
35  $info['error'][] = 'Invalid TIFF byte order identifier ('.substr($TIFFheader, 0, 2).') at offset '.$info['avdataoffset'];
36  return false;
37  break;
38  }
39 
40  $info['fileformat'] = 'tiff';
41  $info['video']['dataformat'] = 'tiff';
42  $info['video']['lossless'] = true;
43  $info['tiff']['ifd'] = array();
44  $CurrentIFD = array();
45 
46  $FieldTypeByteLength = array(1=>1, 2=>1, 3=>2, 4=>4, 5=>8);
47 
48  $nextIFDoffset = $this->TIFFendian2Int($this->fread(4), $info['tiff']['byte_order']);
49 
50  while ($nextIFDoffset > 0) {
51 
52  $CurrentIFD['offset'] = $nextIFDoffset;
53 
54  $this->fseek($info['avdataoffset'] + $nextIFDoffset);
55  $CurrentIFD['fieldcount'] = $this->TIFFendian2Int($this->fread(2), $info['tiff']['byte_order']);
56 
57  for ($i = 0; $i < $CurrentIFD['fieldcount']; $i++) {
58  $CurrentIFD['fields'][$i]['raw']['tag'] = $this->TIFFendian2Int($this->fread(2), $info['tiff']['byte_order']);
59  $CurrentIFD['fields'][$i]['raw']['type'] = $this->TIFFendian2Int($this->fread(2), $info['tiff']['byte_order']);
60  $CurrentIFD['fields'][$i]['raw']['length'] = $this->TIFFendian2Int($this->fread(4), $info['tiff']['byte_order']);
61  $CurrentIFD['fields'][$i]['raw']['offset'] = $this->fread(4);
62 
63  switch ($CurrentIFD['fields'][$i]['raw']['type']) {
64  case 1: // BYTE An 8-bit unsigned integer.
65  if ($CurrentIFD['fields'][$i]['raw']['length'] <= 4) {
66  $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int(substr($CurrentIFD['fields'][$i]['raw']['offset'], 0, 1), $info['tiff']['byte_order']);
67  } else {
68  $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']);
69  }
70  break;
71 
72  case 2: // ASCII 8-bit bytes that store ASCII codes; the last byte must be null.
73  if ($CurrentIFD['fields'][$i]['raw']['length'] <= 4) {
74  $CurrentIFD['fields'][$i]['value'] = substr($CurrentIFD['fields'][$i]['raw']['offset'], 3);
75  } else {
76  $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']);
77  }
78  break;
79 
80  case 3: // SHORT A 16-bit (2-byte) unsigned integer.
81  if ($CurrentIFD['fields'][$i]['raw']['length'] <= 2) {
82  $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int(substr($CurrentIFD['fields'][$i]['raw']['offset'], 0, 2), $info['tiff']['byte_order']);
83  } else {
84  $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']);
85  }
86  break;
87 
88  case 4: // LONG A 32-bit (4-byte) unsigned integer.
89  if ($CurrentIFD['fields'][$i]['raw']['length'] <= 1) {
90  $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']);
91  } else {
92  $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']);
93  }
94  break;
95 
96  case 5: // RATIONAL Two LONG_s: the first represents the numerator of a fraction, the second the denominator.
97  break;
98  }
99  }
100 
101  $info['tiff']['ifd'][] = $CurrentIFD;
102  $CurrentIFD = array();
103  $nextIFDoffset = $this->TIFFendian2Int($this->fread(4), $info['tiff']['byte_order']);
104 
105  }
106 
107  foreach ($info['tiff']['ifd'] as $IFDid => $IFDarray) {
108  foreach ($IFDarray['fields'] as $key => $fieldarray) {
109  switch ($fieldarray['raw']['tag']) {
110  case 256: // ImageWidth
111  case 257: // ImageLength
112  case 258: // BitsPerSample
113  case 259: // Compression
114  if (!isset($fieldarray['value'])) {
115  $this->fseek($fieldarray['offset']);
116  $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $this->fread($fieldarray['raw']['length'] * $FieldTypeByteLength[$fieldarray['raw']['type']]);
117 
118  }
119  break;
120 
121  case 270: // ImageDescription
122  case 271: // Make
123  case 272: // Model
124  case 305: // Software
125  case 306: // DateTime
126  case 315: // Artist
127  case 316: // HostComputer
128  if (isset($fieldarray['value'])) {
129  $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $fieldarray['value'];
130  } else {
131  $this->fseek($fieldarray['offset']);
132  $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $this->fread($fieldarray['raw']['length'] * $FieldTypeByteLength[$fieldarray['raw']['type']]);
133 
134  }
135  break;
136  }
137  switch ($fieldarray['raw']['tag']) {
138  case 256: // ImageWidth
139  $info['video']['resolution_x'] = $fieldarray['value'];
140  break;
141 
142  case 257: // ImageLength
143  $info['video']['resolution_y'] = $fieldarray['value'];
144  break;
145 
146  case 258: // BitsPerSample
147  if (isset($fieldarray['value'])) {
148  $info['video']['bits_per_sample'] = $fieldarray['value'];
149  } else {
150  $info['video']['bits_per_sample'] = 0;
151  for ($i = 0; $i < $fieldarray['raw']['length']; $i++) {
152  $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']);
153  }
154  }
155  break;
156 
157  case 259: // Compression
158  $info['video']['codec'] = $this->TIFFcompressionMethod($fieldarray['value']);
159  break;
160 
161  case 270: // ImageDescription
162  case 271: // Make
163  case 272: // Model
164  case 305: // Software
165  case 306: // DateTime
166  case 315: // Artist
167  case 316: // HostComputer
168  $TIFFcommentName = $this->TIFFcommentName($fieldarray['raw']['tag']);
169  if (isset($info['tiff']['comments'][$TIFFcommentName])) {
170  $info['tiff']['comments'][$TIFFcommentName][] = $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'];
171  } else {
172  $info['tiff']['comments'][$TIFFcommentName] = array($info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data']);
173  }
174  break;
175 
176  default:
177  break;
178  }
179  }
180  }
181 
182  return true;
183  }
TIFFendian2Int($bytestring, $byteorder)
$info
Definition: example_052.php:80
fread($bytes)
Definition: getid3.php:1685
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
+ Here is the call graph for this function:

◆ getid3_tiff()

getid3_tiff::getid3_tiff ( $fd,
$ThisFileInfo 
)

Definition at line 20 of file module.graphic.tiff.php.

References getid3_handler\fread(), getid3_handler\fseek(), TIFFcommentName(), TIFFcompressionMethod(), and TIFFendian2Int().

20  {
21 
22  fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
23  $TIFFheader = fread($fd, 4);
24 
25  switch (substr($TIFFheader, 0, 2)) {
26  case 'II':
27  $ThisFileInfo['tiff']['byte_order'] = 'Intel';
28  break;
29  case 'MM':
30  $ThisFileInfo['tiff']['byte_order'] = 'Motorola';
31  break;
32  default:
33  $ThisFileInfo['error'][] = 'Invalid TIFF byte order identifier ('.substr($TIFFheader, 0, 2).') at offset '.$ThisFileInfo['avdataoffset'];
34  return false;
35  break;
36  }
37 
38  $ThisFileInfo['fileformat'] = 'tiff';
39  $ThisFileInfo['video']['dataformat'] = 'tiff';
40  $ThisFileInfo['video']['lossless'] = true;
41  $ThisFileInfo['tiff']['ifd'] = array();
42  $CurrentIFD = array();
43 
44  $FieldTypeByteLength = array(1=>1, 2=>1, 3=>2, 4=>4, 5=>8);
45 
46  $nextIFDoffset = $this->TIFFendian2Int(fread($fd, 4), $ThisFileInfo['tiff']['byte_order']);
47 
48  while ($nextIFDoffset > 0) {
49 
50  $CurrentIFD['offset'] = $nextIFDoffset;
51 
52  fseek($fd, $ThisFileInfo['avdataoffset'] + $nextIFDoffset, SEEK_SET);
53  $CurrentIFD['fieldcount'] = $this->TIFFendian2Int(fread($fd, 2), $ThisFileInfo['tiff']['byte_order']);
54 
55  for ($i = 0; $i < $CurrentIFD['fieldcount']; $i++) {
56  $CurrentIFD['fields'][$i]['raw']['tag'] = $this->TIFFendian2Int(fread($fd, 2), $ThisFileInfo['tiff']['byte_order']);
57  $CurrentIFD['fields'][$i]['raw']['type'] = $this->TIFFendian2Int(fread($fd, 2), $ThisFileInfo['tiff']['byte_order']);
58  $CurrentIFD['fields'][$i]['raw']['length'] = $this->TIFFendian2Int(fread($fd, 4), $ThisFileInfo['tiff']['byte_order']);
59  $CurrentIFD['fields'][$i]['raw']['offset'] = fread($fd, 4);
60 
61  switch ($CurrentIFD['fields'][$i]['raw']['type']) {
62  case 1: // BYTE An 8-bit unsigned integer.
63  if ($CurrentIFD['fields'][$i]['raw']['length'] <= 4) {
64  $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int(substr($CurrentIFD['fields'][$i]['raw']['offset'], 0, 1), $ThisFileInfo['tiff']['byte_order']);
65  } else {
66  $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $ThisFileInfo['tiff']['byte_order']);
67  }
68  break;
69 
70  case 2: // ASCII 8-bit bytes that store ASCII codes; the last byte must be null.
71  if ($CurrentIFD['fields'][$i]['raw']['length'] <= 4) {
72  $CurrentIFD['fields'][$i]['value'] = substr($CurrentIFD['fields'][$i]['raw']['offset'], 3);
73  } else {
74  $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $ThisFileInfo['tiff']['byte_order']);
75  }
76  break;
77 
78  case 3: // SHORT A 16-bit (2-byte) unsigned integer.
79  if ($CurrentIFD['fields'][$i]['raw']['length'] <= 2) {
80  $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int(substr($CurrentIFD['fields'][$i]['raw']['offset'], 0, 2), $ThisFileInfo['tiff']['byte_order']);
81  } else {
82  $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $ThisFileInfo['tiff']['byte_order']);
83  }
84  break;
85 
86  case 4: // LONG A 32-bit (4-byte) unsigned integer.
87  if ($CurrentIFD['fields'][$i]['raw']['length'] <= 1) {
88  $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $ThisFileInfo['tiff']['byte_order']);
89  } else {
90  $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $ThisFileInfo['tiff']['byte_order']);
91  }
92  break;
93 
94  case 5: // RATIONAL Two LONG_s: the first represents the numerator of a fraction, the second the denominator.
95  break;
96  }
97  }
98 
99  $ThisFileInfo['tiff']['ifd'][] = $CurrentIFD;
100  $CurrentIFD = array();
101  $nextIFDoffset = $this->TIFFendian2Int(fread($fd, 4), $ThisFileInfo['tiff']['byte_order']);
102 
103  }
104 
105  foreach ($ThisFileInfo['tiff']['ifd'] as $IFDid => $IFDarray) {
106  foreach ($IFDarray['fields'] as $key => $fieldarray) {
107  switch ($fieldarray['raw']['tag']) {
108  case 256: // ImageWidth
109  case 257: // ImageLength
110  case 258: // BitsPerSample
111  case 259: // Compression
112  if (!isset($fieldarray['value'])) {
113  fseek($fd, $fieldarray['offset'], SEEK_SET);
114  $ThisFileInfo['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = fread($fd, $fieldarray['raw']['length'] * $FieldTypeByteLength[$fieldarray['raw']['type']]);
115 
116  }
117  break;
118 
119  case 270: // ImageDescription
120  case 271: // Make
121  case 272: // Model
122  case 305: // Software
123  case 306: // DateTime
124  case 315: // Artist
125  case 316: // HostComputer
126  if (isset($fieldarray['value'])) {
127  $ThisFileInfo['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $fieldarray['value'];
128  } else {
129  fseek($fd, $fieldarray['offset'], SEEK_SET);
130  $ThisFileInfo['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = fread($fd, $fieldarray['raw']['length'] * $FieldTypeByteLength[$fieldarray['raw']['type']]);
131 
132  }
133  break;
134  }
135  switch ($fieldarray['raw']['tag']) {
136  case 256: // ImageWidth
137  $ThisFileInfo['video']['resolution_x'] = $fieldarray['value'];
138  break;
139 
140  case 257: // ImageLength
141  $ThisFileInfo['video']['resolution_y'] = $fieldarray['value'];
142  break;
143 
144  case 258: // BitsPerSample
145  if (isset($fieldarray['value'])) {
146  $ThisFileInfo['video']['bits_per_sample'] = $fieldarray['value'];
147  } else {
148  $ThisFileInfo['video']['bits_per_sample'] = 0;
149  for ($i = 0; $i < $fieldarray['raw']['length']; $i++) {
150  $ThisFileInfo['video']['bits_per_sample'] += $this->TIFFendian2Int(substr($ThisFileInfo['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'], $i * $FieldTypeByteLength[$fieldarray['raw']['type']], $FieldTypeByteLength[$fieldarray['raw']['type']]), $ThisFileInfo['tiff']['byte_order']);
151  }
152  }
153  break;
154 
155  case 259: // Compression
156  $ThisFileInfo['video']['codec'] = $this->TIFFcompressionMethod($fieldarray['value']);
157  break;
158 
159  case 270: // ImageDescription
160  case 271: // Make
161  case 272: // Model
162  case 305: // Software
163  case 306: // DateTime
164  case 315: // Artist
165  case 316: // HostComputer
166  @$ThisFileInfo['tiff']['comments'][$this->TIFFcommentName($fieldarray['raw']['tag'])][] = $ThisFileInfo['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'];
167  break;
168 
169  default:
170  break;
171  }
172  }
173  }
174 
175  return true;
176  }
TIFFendian2Int($bytestring, $byteorder)
fread($bytes)
Definition: getid3.php:1685
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
+ Here is the call graph for this function:

◆ TIFFcommentName() [1/2]

getid3_tiff::TIFFcommentName (   $id)

Definition at line 202 of file module.graphic.tiff.php.

Referenced by Analyze(), and getid3_tiff().

202  {
203  static $TIFFcommentName = array();
204  if (empty($TIFFcommentName)) {
205  $TIFFcommentName = array(
206  270 => 'imagedescription',
207  271 => 'make',
208  272 => 'model',
209  305 => 'software',
210  306 => 'datetime',
211  315 => 'artist',
212  316 => 'hostcomputer',
213  );
214  }
215  return (isset($TIFFcommentName[$id]) ? $TIFFcommentName[$id] : 'unknown/invalid ('.$id.')');
216  }
+ Here is the caller graph for this function:

◆ TIFFcommentName() [2/2]

getid3_tiff::TIFFcommentName (   $id)

Definition at line 209 of file module.graphic.tiff.php.

209  {
210  static $TIFFcommentName = array();
211  if (empty($TIFFcommentName)) {
212  $TIFFcommentName = array(
213  270 => 'imagedescription',
214  271 => 'make',
215  272 => 'model',
216  305 => 'software',
217  306 => 'datetime',
218  315 => 'artist',
219  316 => 'hostcomputer',
220  );
221  }
222  return (isset($TIFFcommentName[$id]) ? $TIFFcommentName[$id] : 'unknown/invalid ('.$id.')');
223  }

◆ TIFFcompressionMethod() [1/2]

getid3_tiff::TIFFcompressionMethod (   $id)

Definition at line 188 of file module.graphic.tiff.php.

Referenced by Analyze(), and getid3_tiff().

188  {
189  static $TIFFcompressionMethod = array();
190  if (empty($TIFFcompressionMethod)) {
191  $TIFFcompressionMethod = array(
192  1 => 'Uncompressed',
193  2 => 'Huffman',
194  3 => 'Fax - CCITT 3',
195  5 => 'LZW',
196  32773 => 'PackBits',
197  );
198  }
199  return (isset($TIFFcompressionMethod[$id]) ? $TIFFcompressionMethod[$id] : 'unknown/invalid ('.$id.')');
200  }
+ Here is the caller graph for this function:

◆ TIFFcompressionMethod() [2/2]

getid3_tiff::TIFFcompressionMethod (   $id)

Definition at line 195 of file module.graphic.tiff.php.

195  {
196  static $TIFFcompressionMethod = array();
197  if (empty($TIFFcompressionMethod)) {
198  $TIFFcompressionMethod = array(
199  1 => 'Uncompressed',
200  2 => 'Huffman',
201  3 => 'Fax - CCITT 3',
202  5 => 'LZW',
203  32773 => 'PackBits',
204  );
205  }
206  return (isset($TIFFcompressionMethod[$id]) ? $TIFFcompressionMethod[$id] : 'unknown/invalid ('.$id.')');
207  }

◆ TIFFendian2Int() [1/2]

getid3_tiff::TIFFendian2Int (   $bytestring,
  $byteorder 
)

Definition at line 179 of file module.graphic.tiff.php.

References getid3_lib\BigEndian2Int(), and getid3_lib\LittleEndian2Int().

Referenced by Analyze(), and getid3_tiff().

179  {
180  if ($byteorder == 'Intel') {
181  return getid3_lib::LittleEndian2Int($bytestring);
182  } elseif ($byteorder == 'Motorola') {
183  return getid3_lib::BigEndian2Int($bytestring);
184  }
185  return false;
186  }
LittleEndian2Int($byteword, $signed=false)
Definition: getid3.lib.php:266
BigEndian2Int($byteword, $synchsafe=false, $signed=false)
Definition: getid3.lib.php:234
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ TIFFendian2Int() [2/2]

getid3_tiff::TIFFendian2Int (   $bytestring,
  $byteorder 
)

Definition at line 186 of file module.graphic.tiff.php.

References getid3_lib\BigEndian2Int(), and getid3_lib\LittleEndian2Int().

186  {
187  if ($byteorder == 'Intel') {
188  return getid3_lib::LittleEndian2Int($bytestring);
189  } elseif ($byteorder == 'Motorola') {
190  return getid3_lib::BigEndian2Int($bytestring);
191  }
192  return false;
193  }
LittleEndian2Int($byteword, $signed=false)
Definition: getid3.lib.php:266
BigEndian2Int($byteword, $synchsafe=false, $signed=false)
Definition: getid3.lib.php:234
+ Here is the call graph for this function:

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