ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
Png.php
Go to the documentation of this file.
1 <?php
2 
3 namespace GetId3\Module\Graphic;
4 
7 
10 // available at http://getid3.sourceforge.net //
11 // or http://www.getid3.org //
13 // See readme.txt for more details //
15 // //
16 // module.graphic.png.php //
17 // module for analyzing PNG Image files //
18 // dependencies: NONE //
19 // ///
21 
29 class Png extends BaseHandler
30 {
31 
36  public function analyze()
37  {
38  $info = &$this->getid3->info;
39 
40  // shortcut
41  $info['png'] = array();
42  $thisfile_png = &$info['png'];
43 
44  $info['fileformat'] = 'png';
45  $info['video']['dataformat'] = 'png';
46  $info['video']['lossless'] = false;
47 
48  fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
49  $PNGfiledata = fread($this->getid3->fp, $this->getid3->fread_buffer_size());
50  $offset = 0;
51 
52  $PNGidentifier = substr($PNGfiledata, $offset, 8); // $89 $50 $4E $47 $0D $0A $1A $0A
53  $offset += 8;
54 
55  if ($PNGidentifier != "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") {
56  $info['error'][] = 'First 8 bytes of file ('.Helper::PrintHexBytes($PNGidentifier).') did not match expected PNG identifier';
57  unset($info['fileformat']);
58 
59  return false;
60  }
61 
62  while (((ftell($this->getid3->fp) - (strlen($PNGfiledata) - $offset)) < $info['filesize'])) {
63  $chunk['data_length'] = Helper::BigEndian2Int(substr($PNGfiledata, $offset, 4));
64  $offset += 4;
65  while (((strlen($PNGfiledata) - $offset) < ($chunk['data_length'] + 4)) && (ftell($this->getid3->fp) < $info['filesize'])) {
66  $PNGfiledata .= fread($this->getid3->fp, $this->getid3->fread_buffer_size());
67  }
68  $chunk['type_text'] = substr($PNGfiledata, $offset, 4);
69  $offset += 4;
70  $chunk['type_raw'] = Helper::BigEndian2Int($chunk['type_text']);
71  $chunk['data'] = substr($PNGfiledata, $offset, $chunk['data_length']);
72  $offset += $chunk['data_length'];
73  $chunk['crc'] = Helper::BigEndian2Int(substr($PNGfiledata, $offset, 4));
74  $offset += 4;
75 
76  $chunk['flags']['ancilliary'] = (bool) ($chunk['type_raw'] & 0x20000000);
77  $chunk['flags']['private'] = (bool) ($chunk['type_raw'] & 0x00200000);
78  $chunk['flags']['reserved'] = (bool) ($chunk['type_raw'] & 0x00002000);
79  $chunk['flags']['safe_to_copy'] = (bool) ($chunk['type_raw'] & 0x00000020);
80 
81  // shortcut
82  $thisfile_png[$chunk['type_text']] = array();
83  $thisfile_png_chunk_type_text = &$thisfile_png[$chunk['type_text']];
84 
85  switch ($chunk['type_text']) {
86 
87  case 'IHDR': // Image Header
88  $thisfile_png_chunk_type_text['header'] = $chunk;
89  $thisfile_png_chunk_type_text['width'] = Helper::BigEndian2Int(substr($chunk['data'], 0, 4));
90  $thisfile_png_chunk_type_text['height'] = Helper::BigEndian2Int(substr($chunk['data'], 4, 4));
91  $thisfile_png_chunk_type_text['raw']['bit_depth'] = Helper::BigEndian2Int(substr($chunk['data'], 8, 1));
92  $thisfile_png_chunk_type_text['raw']['color_type'] = Helper::BigEndian2Int(substr($chunk['data'], 9, 1));
93  $thisfile_png_chunk_type_text['raw']['compression_method'] = Helper::BigEndian2Int(substr($chunk['data'], 10, 1));
94  $thisfile_png_chunk_type_text['raw']['filter_method'] = Helper::BigEndian2Int(substr($chunk['data'], 11, 1));
95  $thisfile_png_chunk_type_text['raw']['interlace_method'] = Helper::BigEndian2Int(substr($chunk['data'], 12, 1));
96 
97  $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['raw']['compression_method']);
98  $thisfile_png_chunk_type_text['color_type']['palette'] = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x01);
99  $thisfile_png_chunk_type_text['color_type']['true_color'] = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x02);
100  $thisfile_png_chunk_type_text['color_type']['alpha'] = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x04);
101 
102  $info['video']['resolution_x'] = $thisfile_png_chunk_type_text['width'];
103  $info['video']['resolution_y'] = $thisfile_png_chunk_type_text['height'];
104 
105  $info['video']['bits_per_sample'] = $this->IHDRcalculateBitsPerSample($thisfile_png_chunk_type_text['raw']['color_type'], $thisfile_png_chunk_type_text['raw']['bit_depth']);
106  break;
107 
108  case 'PLTE': // Palette
109  $thisfile_png_chunk_type_text['header'] = $chunk;
110  $paletteoffset = 0;
111  for ($i = 0; $i <= 255; $i++) {
112  //$thisfile_png_chunk_type_text['red'][$i] = GetId3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1));
113  //$thisfile_png_chunk_type_text['green'][$i] = GetId3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1));
114  //$thisfile_png_chunk_type_text['blue'][$i] = GetId3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1));
115  $red = Helper::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1));
116  $green = Helper::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1));
117  $blue = Helper::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1));
118  $thisfile_png_chunk_type_text[$i] = (($red << 16) | ($green << 8) | ($blue));
119  }
120  break;
121 
122  case 'tRNS': // Transparency
123  $thisfile_png_chunk_type_text['header'] = $chunk;
124  switch ($thisfile_png['IHDR']['raw']['color_type']) {
125  case 0:
126  $thisfile_png_chunk_type_text['transparent_color_gray'] = Helper::BigEndian2Int(substr($chunk['data'], 0, 2));
127  break;
128 
129  case 2:
130  $thisfile_png_chunk_type_text['transparent_color_red'] = Helper::BigEndian2Int(substr($chunk['data'], 0, 2));
131  $thisfile_png_chunk_type_text['transparent_color_green'] = Helper::BigEndian2Int(substr($chunk['data'], 2, 2));
132  $thisfile_png_chunk_type_text['transparent_color_blue'] = Helper::BigEndian2Int(substr($chunk['data'], 4, 2));
133  break;
134 
135  case 3:
136  for ($i = 0; $i < strlen($chunk['data']); $i++) {
137  $thisfile_png_chunk_type_text['palette_opacity'][$i] = Helper::BigEndian2Int(substr($chunk['data'], $i, 1));
138  }
139  break;
140 
141  case 4:
142  case 6:
143  $info['error'][] = 'Invalid color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type'];
144 
145  default:
146  $info['warning'][] = 'Unhandled color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type'];
147  break;
148  }
149  break;
150 
151  case 'gAMA': // Image Gamma
152  $thisfile_png_chunk_type_text['header'] = $chunk;
153  $thisfile_png_chunk_type_text['gamma'] = Helper::BigEndian2Int($chunk['data']) / 100000;
154  break;
155 
156  case 'cHRM': // Primary Chromaticities
157  $thisfile_png_chunk_type_text['header'] = $chunk;
158  $thisfile_png_chunk_type_text['white_x'] = Helper::BigEndian2Int(substr($chunk['data'], 0, 4)) / 100000;
159  $thisfile_png_chunk_type_text['white_y'] = Helper::BigEndian2Int(substr($chunk['data'], 4, 4)) / 100000;
160  $thisfile_png_chunk_type_text['red_y'] = Helper::BigEndian2Int(substr($chunk['data'], 8, 4)) / 100000;
161  $thisfile_png_chunk_type_text['red_y'] = Helper::BigEndian2Int(substr($chunk['data'], 12, 4)) / 100000;
162  $thisfile_png_chunk_type_text['green_y'] = Helper::BigEndian2Int(substr($chunk['data'], 16, 4)) / 100000;
163  $thisfile_png_chunk_type_text['green_y'] = Helper::BigEndian2Int(substr($chunk['data'], 20, 4)) / 100000;
164  $thisfile_png_chunk_type_text['blue_y'] = Helper::BigEndian2Int(substr($chunk['data'], 24, 4)) / 100000;
165  $thisfile_png_chunk_type_text['blue_y'] = Helper::BigEndian2Int(substr($chunk['data'], 28, 4)) / 100000;
166  break;
167 
168  case 'sRGB': // Standard RGB Color Space
169  $thisfile_png_chunk_type_text['header'] = $chunk;
170  $thisfile_png_chunk_type_text['reindering_intent'] = Helper::BigEndian2Int($chunk['data']);
171  $thisfile_png_chunk_type_text['reindering_intent_text'] = $this->PNGsRGBintentLookup($thisfile_png_chunk_type_text['reindering_intent']);
172  break;
173 
174  case 'iCCP': // Embedded ICC Profile
175  $thisfile_png_chunk_type_text['header'] = $chunk;
176  list($profilename, $compressiondata) = explode("\x00", $chunk['data'], 2);
177  $thisfile_png_chunk_type_text['profile_name'] = $profilename;
178  $thisfile_png_chunk_type_text['compression_method'] = Helper::BigEndian2Int(substr($compressiondata, 0, 1));
179  $thisfile_png_chunk_type_text['compression_profile'] = substr($compressiondata, 1);
180 
181  $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']);
182  break;
183 
184  case 'tEXt': // Textual Data
185  $thisfile_png_chunk_type_text['header'] = $chunk;
186  list($keyword, $text) = explode("\x00", $chunk['data'], 2);
187  $thisfile_png_chunk_type_text['keyword'] = $keyword;
188  $thisfile_png_chunk_type_text['text'] = $text;
189 
190  $thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text'];
191  break;
192 
193  case 'zTXt': // Compressed Textual Data
194  $thisfile_png_chunk_type_text['header'] = $chunk;
195  list($keyword, $otherdata) = explode("\x00", $chunk['data'], 2);
196  $thisfile_png_chunk_type_text['keyword'] = $keyword;
197  $thisfile_png_chunk_type_text['compression_method'] = Helper::BigEndian2Int(substr($otherdata, 0, 1));
198  $thisfile_png_chunk_type_text['compressed_text'] = substr($otherdata, 1);
199  $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']);
200  switch ($thisfile_png_chunk_type_text['compression_method']) {
201  case 0:
202  $thisfile_png_chunk_type_text['text'] = gzuncompress($thisfile_png_chunk_type_text['compressed_text']);
203  break;
204 
205  default:
206  // unknown compression method
207  break;
208  }
209 
210  if (isset($thisfile_png_chunk_type_text['text'])) {
211  $thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text'];
212  }
213  break;
214 
215  case 'iTXt': // International Textual Data
216  $thisfile_png_chunk_type_text['header'] = $chunk;
217  list($keyword, $otherdata) = explode("\x00", $chunk['data'], 2);
218  $thisfile_png_chunk_type_text['keyword'] = $keyword;
219  $thisfile_png_chunk_type_text['compression'] = (bool) Helper::BigEndian2Int(substr($otherdata, 0, 1));
220  $thisfile_png_chunk_type_text['compression_method'] = Helper::BigEndian2Int(substr($otherdata, 1, 1));
221  $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']);
222  list($languagetag, $translatedkeyword, $text) = explode("\x00", substr($otherdata, 2), 3);
223  $thisfile_png_chunk_type_text['language_tag'] = $languagetag;
224  $thisfile_png_chunk_type_text['translated_keyword'] = $translatedkeyword;
225 
226  if ($thisfile_png_chunk_type_text['compression']) {
227 
228  switch ($thisfile_png_chunk_type_text['compression_method']) {
229  case 0:
230  $thisfile_png_chunk_type_text['text'] = gzuncompress($text);
231  break;
232 
233  default:
234  // unknown compression method
235  break;
236  }
237 
238  } else {
239 
240  $thisfile_png_chunk_type_text['text'] = $text;
241 
242  }
243 
244  if (isset($thisfile_png_chunk_type_text['text'])) {
245  $thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text'];
246  }
247  break;
248 
249  case 'bKGD': // Background Color
250  $thisfile_png_chunk_type_text['header'] = $chunk;
251  switch ($thisfile_png['IHDR']['raw']['color_type']) {
252  case 0:
253  case 4:
254  $thisfile_png_chunk_type_text['background_gray'] = Helper::BigEndian2Int($chunk['data']);
255  break;
256 
257  case 2:
258  case 6:
259  $thisfile_png_chunk_type_text['background_red'] = Helper::BigEndian2Int(substr($chunk['data'], 0 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth']));
260  $thisfile_png_chunk_type_text['background_green'] = Helper::BigEndian2Int(substr($chunk['data'], 1 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth']));
261  $thisfile_png_chunk_type_text['background_blue'] = Helper::BigEndian2Int(substr($chunk['data'], 2 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth']));
262  break;
263 
264  case 3:
265  $thisfile_png_chunk_type_text['background_index'] = Helper::BigEndian2Int($chunk['data']);
266  break;
267 
268  default:
269  break;
270  }
271  break;
272 
273  case 'pHYs': // Physical Pixel Dimensions
274  $thisfile_png_chunk_type_text['header'] = $chunk;
275  $thisfile_png_chunk_type_text['pixels_per_unit_x'] = Helper::BigEndian2Int(substr($chunk['data'], 0, 4));
276  $thisfile_png_chunk_type_text['pixels_per_unit_y'] = Helper::BigEndian2Int(substr($chunk['data'], 4, 4));
277  $thisfile_png_chunk_type_text['unit_specifier'] = Helper::BigEndian2Int(substr($chunk['data'], 8, 1));
278  $thisfile_png_chunk_type_text['unit'] = $this->PNGpHYsUnitLookup($thisfile_png_chunk_type_text['unit_specifier']);
279  break;
280 
281  case 'sBIT': // Significant Bits
282  $thisfile_png_chunk_type_text['header'] = $chunk;
283  switch ($thisfile_png['IHDR']['raw']['color_type']) {
284  case 0:
285  $thisfile_png_chunk_type_text['significant_bits_gray'] = Helper::BigEndian2Int(substr($chunk['data'], 0, 1));
286  break;
287 
288  case 2:
289  case 3:
290  $thisfile_png_chunk_type_text['significant_bits_red'] = Helper::BigEndian2Int(substr($chunk['data'], 0, 1));
291  $thisfile_png_chunk_type_text['significant_bits_green'] = Helper::BigEndian2Int(substr($chunk['data'], 1, 1));
292  $thisfile_png_chunk_type_text['significant_bits_blue'] = Helper::BigEndian2Int(substr($chunk['data'], 2, 1));
293  break;
294 
295  case 4:
296  $thisfile_png_chunk_type_text['significant_bits_gray'] = Helper::BigEndian2Int(substr($chunk['data'], 0, 1));
297  $thisfile_png_chunk_type_text['significant_bits_alpha'] = Helper::BigEndian2Int(substr($chunk['data'], 1, 1));
298  break;
299 
300  case 6:
301  $thisfile_png_chunk_type_text['significant_bits_red'] = Helper::BigEndian2Int(substr($chunk['data'], 0, 1));
302  $thisfile_png_chunk_type_text['significant_bits_green'] = Helper::BigEndian2Int(substr($chunk['data'], 1, 1));
303  $thisfile_png_chunk_type_text['significant_bits_blue'] = Helper::BigEndian2Int(substr($chunk['data'], 2, 1));
304  $thisfile_png_chunk_type_text['significant_bits_alpha'] = Helper::BigEndian2Int(substr($chunk['data'], 3, 1));
305  break;
306 
307  default:
308  break;
309  }
310  break;
311 
312  case 'sPLT': // Suggested Palette
313  $thisfile_png_chunk_type_text['header'] = $chunk;
314  list($palettename, $otherdata) = explode("\x00", $chunk['data'], 2);
315  $thisfile_png_chunk_type_text['palette_name'] = $palettename;
316  $sPLToffset = 0;
317  $thisfile_png_chunk_type_text['sample_depth_bits'] = Helper::BigEndian2Int(substr($otherdata, $sPLToffset, 1));
318  $sPLToffset += 1;
319  $thisfile_png_chunk_type_text['sample_depth_bytes'] = $thisfile_png_chunk_type_text['sample_depth_bits'] / 8;
320  $paletteCounter = 0;
321  while ($sPLToffset < strlen($otherdata)) {
322  $thisfile_png_chunk_type_text['red'][$paletteCounter] = Helper::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes']));
323  $sPLToffset += $thisfile_png_chunk_type_text['sample_depth_bytes'];
324  $thisfile_png_chunk_type_text['green'][$paletteCounter] = Helper::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes']));
325  $sPLToffset += $thisfile_png_chunk_type_text['sample_depth_bytes'];
326  $thisfile_png_chunk_type_text['blue'][$paletteCounter] = Helper::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes']));
327  $sPLToffset += $thisfile_png_chunk_type_text['sample_depth_bytes'];
328  $thisfile_png_chunk_type_text['alpha'][$paletteCounter] = Helper::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes']));
329  $sPLToffset += $thisfile_png_chunk_type_text['sample_depth_bytes'];
330  $thisfile_png_chunk_type_text['frequency'][$paletteCounter] = Helper::BigEndian2Int(substr($otherdata, $sPLToffset, 2));
331  $sPLToffset += 2;
332  $paletteCounter++;
333  }
334  break;
335 
336  case 'hIST': // Palette Histogram
337  $thisfile_png_chunk_type_text['header'] = $chunk;
338  $hISTcounter = 0;
339  while ($hISTcounter < strlen($chunk['data'])) {
340  $thisfile_png_chunk_type_text[$hISTcounter] = Helper::BigEndian2Int(substr($chunk['data'], $hISTcounter / 2, 2));
341  $hISTcounter += 2;
342  }
343  break;
344 
345  case 'tIME': // Image Last-Modification Time
346  $thisfile_png_chunk_type_text['header'] = $chunk;
347  $thisfile_png_chunk_type_text['year'] = Helper::BigEndian2Int(substr($chunk['data'], 0, 2));
348  $thisfile_png_chunk_type_text['month'] = Helper::BigEndian2Int(substr($chunk['data'], 2, 1));
349  $thisfile_png_chunk_type_text['day'] = Helper::BigEndian2Int(substr($chunk['data'], 3, 1));
350  $thisfile_png_chunk_type_text['hour'] = Helper::BigEndian2Int(substr($chunk['data'], 4, 1));
351  $thisfile_png_chunk_type_text['minute'] = Helper::BigEndian2Int(substr($chunk['data'], 5, 1));
352  $thisfile_png_chunk_type_text['second'] = Helper::BigEndian2Int(substr($chunk['data'], 6, 1));
353  $thisfile_png_chunk_type_text['unix'] = gmmktime($thisfile_png_chunk_type_text['hour'], $thisfile_png_chunk_type_text['minute'], $thisfile_png_chunk_type_text['second'], $thisfile_png_chunk_type_text['month'], $thisfile_png_chunk_type_text['day'], $thisfile_png_chunk_type_text['year']);
354  break;
355 
356  case 'oFFs': // Image Offset
357  $thisfile_png_chunk_type_text['header'] = $chunk;
358  $thisfile_png_chunk_type_text['position_x'] = Helper::BigEndian2Int(substr($chunk['data'], 0, 4), false, true);
359  $thisfile_png_chunk_type_text['position_y'] = Helper::BigEndian2Int(substr($chunk['data'], 4, 4), false, true);
360  $thisfile_png_chunk_type_text['unit_specifier'] = Helper::BigEndian2Int(substr($chunk['data'], 8, 1));
361  $thisfile_png_chunk_type_text['unit'] = $this->PNGoFFsUnitLookup($thisfile_png_chunk_type_text['unit_specifier']);
362  break;
363 
364  case 'pCAL': // Calibration Of Pixel Values
365  $thisfile_png_chunk_type_text['header'] = $chunk;
366  list($calibrationname, $otherdata) = explode("\x00", $chunk['data'], 2);
367  $thisfile_png_chunk_type_text['calibration_name'] = $calibrationname;
368  $pCALoffset = 0;
369  $thisfile_png_chunk_type_text['original_zero'] = Helper::BigEndian2Int(substr($chunk['data'], $pCALoffset, 4), false, true);
370  $pCALoffset += 4;
371  $thisfile_png_chunk_type_text['original_max'] = Helper::BigEndian2Int(substr($chunk['data'], $pCALoffset, 4), false, true);
372  $pCALoffset += 4;
373  $thisfile_png_chunk_type_text['equation_type'] = Helper::BigEndian2Int(substr($chunk['data'], $pCALoffset, 1));
374  $pCALoffset += 1;
375  $thisfile_png_chunk_type_text['equation_type_text'] = $this->PNGpCALequationTypeLookup($thisfile_png_chunk_type_text['equation_type']);
376  $thisfile_png_chunk_type_text['parameter_count'] = Helper::BigEndian2Int(substr($chunk['data'], $pCALoffset, 1));
377  $pCALoffset += 1;
378  $thisfile_png_chunk_type_text['parameters'] = explode("\x00", substr($chunk['data'], $pCALoffset));
379  break;
380 
381  case 'sCAL': // Physical Scale Of Image Subject
382  $thisfile_png_chunk_type_text['header'] = $chunk;
383  $thisfile_png_chunk_type_text['unit_specifier'] = Helper::BigEndian2Int(substr($chunk['data'], 0, 1));
384  $thisfile_png_chunk_type_text['unit'] = $this->PNGsCALUnitLookup($thisfile_png_chunk_type_text['unit_specifier']);
385  list($pixelwidth, $pixelheight) = explode("\x00", substr($chunk['data'], 1));
386  $thisfile_png_chunk_type_text['pixel_width'] = $pixelwidth;
387  $thisfile_png_chunk_type_text['pixel_height'] = $pixelheight;
388  break;
389 
390  case 'gIFg': // GIF Graphic Control Extension
391  $gIFgCounter = 0;
392  if (isset($thisfile_png_chunk_type_text) && is_array($thisfile_png_chunk_type_text)) {
393  $gIFgCounter = count($thisfile_png_chunk_type_text);
394  }
395  $thisfile_png_chunk_type_text[$gIFgCounter]['header'] = $chunk;
396  $thisfile_png_chunk_type_text[$gIFgCounter]['disposal_method'] = Helper::BigEndian2Int(substr($chunk['data'], 0, 1));
397  $thisfile_png_chunk_type_text[$gIFgCounter]['user_input_flag'] = Helper::BigEndian2Int(substr($chunk['data'], 1, 1));
398  $thisfile_png_chunk_type_text[$gIFgCounter]['delay_time'] = Helper::BigEndian2Int(substr($chunk['data'], 2, 2));
399  break;
400 
401  case 'gIFx': // GIF Application Extension
402  $gIFxCounter = 0;
403  if (isset($thisfile_png_chunk_type_text) && is_array($thisfile_png_chunk_type_text)) {
404  $gIFxCounter = count($thisfile_png_chunk_type_text);
405  }
406  $thisfile_png_chunk_type_text[$gIFxCounter]['header'] = $chunk;
407  $thisfile_png_chunk_type_text[$gIFxCounter]['application_identifier'] = substr($chunk['data'], 0, 8);
408  $thisfile_png_chunk_type_text[$gIFxCounter]['authentication_code'] = substr($chunk['data'], 8, 3);
409  $thisfile_png_chunk_type_text[$gIFxCounter]['application_data'] = substr($chunk['data'], 11);
410  break;
411 
412  case 'IDAT': // Image Data
413  $idatinformationfieldindex = 0;
414  if (isset($thisfile_png['IDAT']) && is_array($thisfile_png['IDAT'])) {
415  $idatinformationfieldindex = count($thisfile_png['IDAT']);
416  }
417  unset($chunk['data']);
418  $thisfile_png_chunk_type_text[$idatinformationfieldindex]['header'] = $chunk;
419  break;
420 
421  case 'IEND': // Image Trailer
422  $thisfile_png_chunk_type_text['header'] = $chunk;
423  break;
424 
425  default:
426  //unset($chunk['data']);
427  $thisfile_png_chunk_type_text['header'] = $chunk;
428  $info['warning'][] = 'Unhandled chunk type: '.$chunk['type_text'];
429  break;
430  }
431  }
432 
433  return true;
434  }
435 
442  public function PNGsRGBintentLookup($sRGB)
443  {
444  static $PNGsRGBintentLookup = array(
445  0 => 'Perceptual',
446  1 => 'Relative colorimetric',
447  2 => 'Saturation',
448  3 => 'Absolute colorimetric'
449  );
450 
451  return (isset($PNGsRGBintentLookup[$sRGB]) ? $PNGsRGBintentLookup[$sRGB] : 'invalid');
452  }
453 
460  public function PNGcompressionMethodLookup($compressionmethod)
461  {
462  static $PNGcompressionMethodLookup = array(
463  0 => 'deflate/inflate'
464  );
465 
466  return (isset($PNGcompressionMethodLookup[$compressionmethod]) ? $PNGcompressionMethodLookup[$compressionmethod] : 'invalid');
467  }
468 
475  public function PNGpHYsUnitLookup($unitid)
476  {
477  static $PNGpHYsUnitLookup = array(
478  0 => 'unknown',
479  1 => 'meter'
480  );
481 
482  return (isset($PNGpHYsUnitLookup[$unitid]) ? $PNGpHYsUnitLookup[$unitid] : 'invalid');
483  }
484 
491  public function PNGoFFsUnitLookup($unitid)
492  {
493  static $PNGoFFsUnitLookup = array(
494  0 => 'pixel',
495  1 => 'micrometer'
496  );
497 
498  return (isset($PNGoFFsUnitLookup[$unitid]) ? $PNGoFFsUnitLookup[$unitid] : 'invalid');
499  }
500 
507  public function PNGpCALequationTypeLookup($equationtype)
508  {
509  static $PNGpCALequationTypeLookup = array(
510  0 => 'Linear mapping',
511  1 => 'Base-e exponential mapping',
512  2 => 'Arbitrary-base exponential mapping',
513  3 => 'Hyperbolic mapping'
514  );
515 
516  return (isset($PNGpCALequationTypeLookup[$equationtype]) ? $PNGpCALequationTypeLookup[$equationtype] : 'invalid');
517  }
518 
525  public function PNGsCALUnitLookup($unitid)
526  {
527  static $PNGsCALUnitLookup = array(
528  0 => 'meter',
529  1 => 'radian'
530  );
531 
532  return (isset($PNGsCALUnitLookup[$unitid]) ? $PNGsCALUnitLookup[$unitid] : 'invalid');
533  }
534 
541  public function IHDRcalculateBitsPerSample($color_type, $bit_depth)
542  {
543  switch ($color_type) {
544  case 0: // Each pixel is a grayscale sample.
545 
546  return $bit_depth;
547  break;
548 
549  case 2: // Each pixel is an R,G,B triple
550 
551  return 3 * $bit_depth;
552  break;
553 
554  case 3: // Each pixel is a palette index; a PLTE chunk must appear.
555 
556  return $bit_depth;
557  break;
558 
559  case 4: // Each pixel is a grayscale sample, followed by an alpha sample.
560 
561  return 2 * $bit_depth;
562  break;
563 
564  case 6: // Each pixel is an R,G,B triple, followed by an alpha sample.
565 
566  return 4 * $bit_depth;
567  break;
568  }
569 
570  return false;
571  }
572 
573 }
$blue
Definition: example_030.php:81
GetId3() by James Heinrich info@getid3.org //.
Definition: BaseHandler.php:25
fseek($bytes, $whence=SEEK_SET)
PNGpCALequationTypeLookup($equationtype)
array $PNGpCALequationTypeLookup
Definition: Png.php:507
$info
Definition: example_052.php:80
$red
Definition: example_030.php:80
PNGsCALUnitLookup($unitid)
array $PNGsCALUnitLookup
Definition: Png.php:525
PNGsRGBintentLookup($sRGB)
array $PNGsRGBintentLookup
Definition: Png.php:442
$green
Definition: example_030.php:83
PNGcompressionMethodLookup($compressionmethod)
array $PNGcompressionMethodLookup
Definition: Png.php:460
GetId3() by James Heinrich info@getid3.org //.
Definition: Png.php:29
Create styles array
The data for the language used.
PNGpHYsUnitLookup($unitid)
array $PNGpHYsUnitLookup
Definition: Png.php:475
static BigEndian2Int($byteword, $synchsafe=false, $signed=false)
Definition: Helper.php:374
IHDRcalculateBitsPerSample($color_type, $bit_depth)
Definition: Png.php:541
$text
PNGoFFsUnitLookup($unitid)
array $PNGoFFsUnitLookup
Definition: Png.php:491