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.graphic.png.php //
12 // module for analyzing PNG Image files //
13 // dependencies: NONE //
15 /////////////////////////////////////////////////////////////////
17 if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
21 class getid3_png
extends getid3_handler
24 * If data chunk is larger than this do not read it completely (getID3 only needs the first
25 * few dozen bytes for parsing).
29 public $max_data_bytes = 10000000;
34 public function Analyze() {
36 $info = &$this->getid3
->info
;
39 $info['png'] = array();
40 $thisfile_png = &$info['png'];
42 $info['fileformat'] = 'png';
43 $info['video']['dataformat'] = 'png';
44 $info['video']['lossless'] = false;
46 $this->fseek($info['avdataoffset']);
47 $PNGfiledata = $this->fread($this->getid3
->fread_buffer_size());
50 $PNGidentifier = substr($PNGfiledata, $offset, 8); // $89 $50 $4E $47 $0D $0A $1A $0A
53 if ($PNGidentifier != "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") {
54 $this->error('First 8 bytes of file ('.getid3_lib
::PrintHexBytes($PNGidentifier).') did not match expected PNG identifier');
55 unset($info['fileformat']);
59 while ((($this->ftell() - (strlen($PNGfiledata) - $offset)) < $info['filesize'])) {
60 $chunk['data_length'] = getid3_lib
::BigEndian2Int(substr($PNGfiledata, $offset, 4));
61 if ($chunk['data_length'] === false) {
62 $this->error('Failed to read data_length at offset '.$offset);
66 $truncated_data = false;
67 while (((strlen($PNGfiledata) - $offset) < ($chunk['data_length'] +
4)) && ($this->ftell() < $info['filesize'])) {
68 if (strlen($PNGfiledata) < $this->max_data_bytes
) {
69 $PNGfiledata .= $this->fread($this->getid3
->fread_buffer_size());
71 $this->warning('At offset '.$offset.' chunk "'.substr($PNGfiledata, $offset, 4).'" exceeded max_data_bytes value of '.$this->max_data_bytes
.', data chunk will be truncated at '.(strlen($PNGfiledata) - 8).' bytes');
75 $chunk['type_text'] = substr($PNGfiledata, $offset, 4);
77 $chunk['type_raw'] = getid3_lib
::BigEndian2Int($chunk['type_text']);
78 $chunk['data'] = substr($PNGfiledata, $offset, $chunk['data_length']);
79 $offset +
= $chunk['data_length'];
80 $chunk['crc'] = getid3_lib
::BigEndian2Int(substr($PNGfiledata, $offset, 4));
83 $chunk['flags']['ancilliary'] = (bool) ($chunk['type_raw'] & 0x20000000);
84 $chunk['flags']['private'] = (bool) ($chunk['type_raw'] & 0x00200000);
85 $chunk['flags']['reserved'] = (bool) ($chunk['type_raw'] & 0x00002000);
86 $chunk['flags']['safe_to_copy'] = (bool) ($chunk['type_raw'] & 0x00000020);
89 $thisfile_png[$chunk['type_text']] = array();
90 $thisfile_png_chunk_type_text = &$thisfile_png[$chunk['type_text']];
92 switch ($chunk['type_text']) {
94 case 'IHDR': // Image Header
95 $thisfile_png_chunk_type_text['header'] = $chunk;
96 $thisfile_png_chunk_type_text['width'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 4));
97 $thisfile_png_chunk_type_text['height'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 4, 4));
98 $thisfile_png_chunk_type_text['raw']['bit_depth'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 8, 1));
99 $thisfile_png_chunk_type_text['raw']['color_type'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 9, 1));
100 $thisfile_png_chunk_type_text['raw']['compression_method'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 10, 1));
101 $thisfile_png_chunk_type_text['raw']['filter_method'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 11, 1));
102 $thisfile_png_chunk_type_text['raw']['interlace_method'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 12, 1));
104 $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['raw']['compression_method']);
105 $thisfile_png_chunk_type_text['color_type']['palette'] = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x01);
106 $thisfile_png_chunk_type_text['color_type']['true_color'] = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x02);
107 $thisfile_png_chunk_type_text['color_type']['alpha'] = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x04);
109 $info['video']['resolution_x'] = $thisfile_png_chunk_type_text['width'];
110 $info['video']['resolution_y'] = $thisfile_png_chunk_type_text['height'];
112 $info['video']['bits_per_sample'] = $this->IHDRcalculateBitsPerSample($thisfile_png_chunk_type_text['raw']['color_type'], $thisfile_png_chunk_type_text['raw']['bit_depth']);
116 case 'PLTE': // Palette
117 $thisfile_png_chunk_type_text['header'] = $chunk;
119 for ($i = 0; $i <= 255; $i++
) {
120 //$thisfile_png_chunk_type_text['red'][$i] = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1));
121 //$thisfile_png_chunk_type_text['green'][$i] = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1));
122 //$thisfile_png_chunk_type_text['blue'][$i] = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1));
123 $red = getid3_lib
::BigEndian2Int(substr($chunk['data'], $paletteoffset++
, 1));
124 $green = getid3_lib
::BigEndian2Int(substr($chunk['data'], $paletteoffset++
, 1));
125 $blue = getid3_lib
::BigEndian2Int(substr($chunk['data'], $paletteoffset++
, 1));
126 $thisfile_png_chunk_type_text[$i] = (($red << 16) |
($green << 8) |
($blue));
131 case 'tRNS': // Transparency
132 $thisfile_png_chunk_type_text['header'] = $chunk;
133 switch ($thisfile_png['IHDR']['raw']['color_type']) {
135 $thisfile_png_chunk_type_text['transparent_color_gray'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 2));
139 $thisfile_png_chunk_type_text['transparent_color_red'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 2));
140 $thisfile_png_chunk_type_text['transparent_color_green'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 2, 2));
141 $thisfile_png_chunk_type_text['transparent_color_blue'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 4, 2));
145 for ($i = 0; $i < strlen($chunk['data']); $i++
) {
146 $thisfile_png_chunk_type_text['palette_opacity'][$i] = getid3_lib
::BigEndian2Int(substr($chunk['data'], $i, 1));
152 $this->error('Invalid color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type']);
156 $this->warning('Unhandled color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type']);
162 case 'gAMA': // Image Gamma
163 $thisfile_png_chunk_type_text['header'] = $chunk;
164 $thisfile_png_chunk_type_text['gamma'] = getid3_lib
::BigEndian2Int($chunk['data']) / 100000;
168 case 'cHRM': // Primary Chromaticities
169 $thisfile_png_chunk_type_text['header'] = $chunk;
170 $thisfile_png_chunk_type_text['white_x'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 4)) / 100000;
171 $thisfile_png_chunk_type_text['white_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 4, 4)) / 100000;
172 $thisfile_png_chunk_type_text['red_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 8, 4)) / 100000;
173 $thisfile_png_chunk_type_text['red_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 12, 4)) / 100000;
174 $thisfile_png_chunk_type_text['green_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 16, 4)) / 100000;
175 $thisfile_png_chunk_type_text['green_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 20, 4)) / 100000;
176 $thisfile_png_chunk_type_text['blue_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 24, 4)) / 100000;
177 $thisfile_png_chunk_type_text['blue_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 28, 4)) / 100000;
181 case 'sRGB': // Standard RGB Color Space
182 $thisfile_png_chunk_type_text['header'] = $chunk;
183 $thisfile_png_chunk_type_text['reindering_intent'] = getid3_lib
::BigEndian2Int($chunk['data']);
184 $thisfile_png_chunk_type_text['reindering_intent_text'] = $this->PNGsRGBintentLookup($thisfile_png_chunk_type_text['reindering_intent']);
188 case 'iCCP': // Embedded ICC Profile
189 $thisfile_png_chunk_type_text['header'] = $chunk;
190 list($profilename, $compressiondata) = explode("\x00", $chunk['data'], 2);
191 $thisfile_png_chunk_type_text['profile_name'] = $profilename;
192 $thisfile_png_chunk_type_text['compression_method'] = getid3_lib
::BigEndian2Int(substr($compressiondata, 0, 1));
193 $thisfile_png_chunk_type_text['compression_profile'] = substr($compressiondata, 1);
195 $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']);
199 case 'tEXt': // Textual Data
200 $thisfile_png_chunk_type_text['header'] = $chunk;
201 list($keyword, $text) = explode("\x00", $chunk['data'], 2);
202 $thisfile_png_chunk_type_text['keyword'] = $keyword;
203 $thisfile_png_chunk_type_text['text'] = $text;
205 $thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text'];
209 case 'zTXt': // Compressed Textual Data
210 $thisfile_png_chunk_type_text['header'] = $chunk;
211 list($keyword, $otherdata) = explode("\x00", $chunk['data'], 2);
212 $thisfile_png_chunk_type_text['keyword'] = $keyword;
213 $thisfile_png_chunk_type_text['compression_method'] = getid3_lib
::BigEndian2Int(substr($otherdata, 0, 1));
214 $thisfile_png_chunk_type_text['compressed_text'] = substr($otherdata, 1);
215 $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']);
216 switch ($thisfile_png_chunk_type_text['compression_method']) {
218 $thisfile_png_chunk_type_text['text'] = gzuncompress($thisfile_png_chunk_type_text['compressed_text']);
222 // unknown compression method
226 if (isset($thisfile_png_chunk_type_text['text'])) {
227 $thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text'];
232 case 'iTXt': // International Textual Data
233 $thisfile_png_chunk_type_text['header'] = $chunk;
234 list($keyword, $otherdata) = explode("\x00", $chunk['data'], 2);
235 $thisfile_png_chunk_type_text['keyword'] = $keyword;
236 $thisfile_png_chunk_type_text['compression'] = (bool) getid3_lib
::BigEndian2Int(substr($otherdata, 0, 1));
237 $thisfile_png_chunk_type_text['compression_method'] = getid3_lib
::BigEndian2Int(substr($otherdata, 1, 1));
238 $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']);
239 list($languagetag, $translatedkeyword, $text) = explode("\x00", substr($otherdata, 2), 3);
240 $thisfile_png_chunk_type_text['language_tag'] = $languagetag;
241 $thisfile_png_chunk_type_text['translated_keyword'] = $translatedkeyword;
243 if ($thisfile_png_chunk_type_text['compression']) {
245 switch ($thisfile_png_chunk_type_text['compression_method']) {
247 $thisfile_png_chunk_type_text['text'] = gzuncompress($text);
251 // unknown compression method
257 $thisfile_png_chunk_type_text['text'] = $text;
261 if (isset($thisfile_png_chunk_type_text['text'])) {
262 $thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text'];
267 case 'bKGD': // Background Color
268 $thisfile_png_chunk_type_text['header'] = $chunk;
269 switch ($thisfile_png['IHDR']['raw']['color_type']) {
272 $thisfile_png_chunk_type_text['background_gray'] = getid3_lib
::BigEndian2Int($chunk['data']);
277 $thisfile_png_chunk_type_text['background_red'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth']));
278 $thisfile_png_chunk_type_text['background_green'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 1 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth']));
279 $thisfile_png_chunk_type_text['background_blue'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 2 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth']));
283 $thisfile_png_chunk_type_text['background_index'] = getid3_lib
::BigEndian2Int($chunk['data']);
292 case 'pHYs': // Physical Pixel Dimensions
293 $thisfile_png_chunk_type_text['header'] = $chunk;
294 $thisfile_png_chunk_type_text['pixels_per_unit_x'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 4));
295 $thisfile_png_chunk_type_text['pixels_per_unit_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 4, 4));
296 $thisfile_png_chunk_type_text['unit_specifier'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 8, 1));
297 $thisfile_png_chunk_type_text['unit'] = $this->PNGpHYsUnitLookup($thisfile_png_chunk_type_text['unit_specifier']);
301 case 'sBIT': // Significant Bits
302 $thisfile_png_chunk_type_text['header'] = $chunk;
303 switch ($thisfile_png['IHDR']['raw']['color_type']) {
305 $thisfile_png_chunk_type_text['significant_bits_gray'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 1));
310 $thisfile_png_chunk_type_text['significant_bits_red'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 1));
311 $thisfile_png_chunk_type_text['significant_bits_green'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 1, 1));
312 $thisfile_png_chunk_type_text['significant_bits_blue'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 2, 1));
316 $thisfile_png_chunk_type_text['significant_bits_gray'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 1));
317 $thisfile_png_chunk_type_text['significant_bits_alpha'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 1, 1));
321 $thisfile_png_chunk_type_text['significant_bits_red'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 1));
322 $thisfile_png_chunk_type_text['significant_bits_green'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 1, 1));
323 $thisfile_png_chunk_type_text['significant_bits_blue'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 2, 1));
324 $thisfile_png_chunk_type_text['significant_bits_alpha'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 3, 1));
333 case 'sPLT': // Suggested Palette
334 $thisfile_png_chunk_type_text['header'] = $chunk;
335 list($palettename, $otherdata) = explode("\x00", $chunk['data'], 2);
336 $thisfile_png_chunk_type_text['palette_name'] = $palettename;
338 $thisfile_png_chunk_type_text['sample_depth_bits'] = getid3_lib
::BigEndian2Int(substr($otherdata, $sPLToffset, 1));
340 $thisfile_png_chunk_type_text['sample_depth_bytes'] = $thisfile_png_chunk_type_text['sample_depth_bits'] / 8;
342 while ($sPLToffset < strlen($otherdata)) {
343 $thisfile_png_chunk_type_text['red'][$paletteCounter] = getid3_lib
::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes']));
344 $sPLToffset +
= $thisfile_png_chunk_type_text['sample_depth_bytes'];
345 $thisfile_png_chunk_type_text['green'][$paletteCounter] = getid3_lib
::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes']));
346 $sPLToffset +
= $thisfile_png_chunk_type_text['sample_depth_bytes'];
347 $thisfile_png_chunk_type_text['blue'][$paletteCounter] = getid3_lib
::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes']));
348 $sPLToffset +
= $thisfile_png_chunk_type_text['sample_depth_bytes'];
349 $thisfile_png_chunk_type_text['alpha'][$paletteCounter] = getid3_lib
::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes']));
350 $sPLToffset +
= $thisfile_png_chunk_type_text['sample_depth_bytes'];
351 $thisfile_png_chunk_type_text['frequency'][$paletteCounter] = getid3_lib
::BigEndian2Int(substr($otherdata, $sPLToffset, 2));
358 case 'hIST': // Palette Histogram
359 $thisfile_png_chunk_type_text['header'] = $chunk;
361 while ($hISTcounter < strlen($chunk['data'])) {
362 $thisfile_png_chunk_type_text[$hISTcounter] = getid3_lib
::BigEndian2Int(substr($chunk['data'], $hISTcounter / 2, 2));
368 case 'tIME': // Image Last-Modification Time
369 $thisfile_png_chunk_type_text['header'] = $chunk;
370 $thisfile_png_chunk_type_text['year'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 2));
371 $thisfile_png_chunk_type_text['month'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 2, 1));
372 $thisfile_png_chunk_type_text['day'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 3, 1));
373 $thisfile_png_chunk_type_text['hour'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 4, 1));
374 $thisfile_png_chunk_type_text['minute'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 5, 1));
375 $thisfile_png_chunk_type_text['second'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 6, 1));
376 $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']);
380 case 'oFFs': // Image Offset
381 $thisfile_png_chunk_type_text['header'] = $chunk;
382 $thisfile_png_chunk_type_text['position_x'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 4), false, true);
383 $thisfile_png_chunk_type_text['position_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 4, 4), false, true);
384 $thisfile_png_chunk_type_text['unit_specifier'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 8, 1));
385 $thisfile_png_chunk_type_text['unit'] = $this->PNGoFFsUnitLookup($thisfile_png_chunk_type_text['unit_specifier']);
389 case 'pCAL': // Calibration Of Pixel Values
390 $thisfile_png_chunk_type_text['header'] = $chunk;
391 list($calibrationname, $otherdata) = explode("\x00", $chunk['data'], 2);
392 $thisfile_png_chunk_type_text['calibration_name'] = $calibrationname;
394 $thisfile_png_chunk_type_text['original_zero'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], $pCALoffset, 4), false, true);
396 $thisfile_png_chunk_type_text['original_max'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], $pCALoffset, 4), false, true);
398 $thisfile_png_chunk_type_text['equation_type'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], $pCALoffset, 1));
400 $thisfile_png_chunk_type_text['equation_type_text'] = $this->PNGpCALequationTypeLookup($thisfile_png_chunk_type_text['equation_type']);
401 $thisfile_png_chunk_type_text['parameter_count'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], $pCALoffset, 1));
403 $thisfile_png_chunk_type_text['parameters'] = explode("\x00", substr($chunk['data'], $pCALoffset));
407 case 'sCAL': // Physical Scale Of Image Subject
408 $thisfile_png_chunk_type_text['header'] = $chunk;
409 $thisfile_png_chunk_type_text['unit_specifier'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 1));
410 $thisfile_png_chunk_type_text['unit'] = $this->PNGsCALUnitLookup($thisfile_png_chunk_type_text['unit_specifier']);
411 list($pixelwidth, $pixelheight) = explode("\x00", substr($chunk['data'], 1));
412 $thisfile_png_chunk_type_text['pixel_width'] = $pixelwidth;
413 $thisfile_png_chunk_type_text['pixel_height'] = $pixelheight;
417 case 'gIFg': // GIF Graphic Control Extension
419 if (isset($thisfile_png_chunk_type_text) && is_array($thisfile_png_chunk_type_text)) {
420 $gIFgCounter = count($thisfile_png_chunk_type_text);
422 $thisfile_png_chunk_type_text[$gIFgCounter]['header'] = $chunk;
423 $thisfile_png_chunk_type_text[$gIFgCounter]['disposal_method'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 1));
424 $thisfile_png_chunk_type_text[$gIFgCounter]['user_input_flag'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 1, 1));
425 $thisfile_png_chunk_type_text[$gIFgCounter]['delay_time'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 2, 2));
429 case 'gIFx': // GIF Application Extension
431 if (isset($thisfile_png_chunk_type_text) && is_array($thisfile_png_chunk_type_text)) {
432 $gIFxCounter = count($thisfile_png_chunk_type_text);
434 $thisfile_png_chunk_type_text[$gIFxCounter]['header'] = $chunk;
435 $thisfile_png_chunk_type_text[$gIFxCounter]['application_identifier'] = substr($chunk['data'], 0, 8);
436 $thisfile_png_chunk_type_text[$gIFxCounter]['authentication_code'] = substr($chunk['data'], 8, 3);
437 $thisfile_png_chunk_type_text[$gIFxCounter]['application_data'] = substr($chunk['data'], 11);
441 case 'IDAT': // Image Data
442 $idatinformationfieldindex = 0;
443 if (isset($thisfile_png['IDAT']) && is_array($thisfile_png['IDAT'])) {
444 $idatinformationfieldindex = count($thisfile_png['IDAT']);
446 unset($chunk['data']);
447 $thisfile_png_chunk_type_text[$idatinformationfieldindex]['header'] = $chunk;
450 case 'IEND': // Image Trailer
451 $thisfile_png_chunk_type_text['header'] = $chunk;
454 case 'acTL': // Animation Control chunk
455 // https://wiki.mozilla.org/APNG_Specification#.60acTL.60:_The_Animation_Control_Chunk
456 $thisfile_png['animation']['num_frames'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 4)); // Number of frames
457 $thisfile_png['animation']['num_plays'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 4, 4)); // Number of times to loop this APNG. 0 indicates infinite looping.
459 unset($chunk['data']);
460 $thisfile_png_chunk_type_text['header'] = $chunk;
463 case 'fcTL': // Frame Control chunk
464 // https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk
466 $fcTL['sequence_number'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 4)); // Sequence number of the animation chunk, starting from 0
467 $fcTL['width'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 4, 4)); // Width of the following frame
468 $fcTL['height'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 8, 4)); // Height of the following frame
469 $fcTL['x_offset'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 12, 4)); // X position at which to render the following frame
470 $fcTL['y_offset'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 16, 4)); // Y position at which to render the following frame
471 $fcTL['delay_num'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 20, 2)); // Frame delay fraction numerator
472 $fcTL['delay_den'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 22, 2)); // Frame delay fraction numerator
473 $fcTL['dispose_op'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 23, 1)); // Type of frame area disposal to be done after rendering this frame
474 $fcTL['blend_op'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 23, 1)); // Type of frame area rendering for this frame
475 if ($fcTL['delay_den']) {
476 $fcTL['delay'] = $fcTL['delay_num'] / $fcTL['delay_den'];
478 $thisfile_png['animation']['fcTL'][$fcTL['sequence_number']] = $fcTL;
480 unset($chunk['data']);
481 $thisfile_png_chunk_type_text['header'] = $chunk;
484 case 'fdAT': // Frame Data chunk
485 // https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk
486 // "The `fdAT` chunk has the same purpose as an `IDAT` chunk. It has the same structure as an `IDAT` chunk, except preceded by a sequence number."
487 unset($chunk['data']);
488 $thisfile_png_chunk_type_text['header'] = $chunk;
492 //unset($chunk['data']);
493 $thisfile_png_chunk_type_text['header'] = $chunk;
494 $this->warning('Unhandled chunk type: '.$chunk['type_text']);
498 if (!empty($thisfile_png['animation']['num_frames']) && !empty($thisfile_png['animation']['fcTL'])) {
499 $info['video']['dataformat'] = 'apng';
500 $info['playtime_seconds'] = 0;
501 foreach ($thisfile_png['animation']['fcTL'] as $seqno => $fcTL) {
502 $info['playtime_seconds'] +
= $fcTL['delay'];
513 public function PNGsRGBintentLookup($sRGB) {
514 static $PNGsRGBintentLookup = array(
516 1 => 'Relative colorimetric',
518 3 => 'Absolute colorimetric'
520 return (isset($PNGsRGBintentLookup[$sRGB]) ?
$PNGsRGBintentLookup[$sRGB] : 'invalid');
524 * @param int $compressionmethod
528 public function PNGcompressionMethodLookup($compressionmethod) {
529 static $PNGcompressionMethodLookup = array(
530 0 => 'deflate/inflate'
532 return (isset($PNGcompressionMethodLookup[$compressionmethod]) ?
$PNGcompressionMethodLookup[$compressionmethod] : 'invalid');
540 public function PNGpHYsUnitLookup($unitid) {
541 static $PNGpHYsUnitLookup = array(
545 return (isset($PNGpHYsUnitLookup[$unitid]) ?
$PNGpHYsUnitLookup[$unitid] : 'invalid');
553 public function PNGoFFsUnitLookup($unitid) {
554 static $PNGoFFsUnitLookup = array(
558 return (isset($PNGoFFsUnitLookup[$unitid]) ?
$PNGoFFsUnitLookup[$unitid] : 'invalid');
562 * @param int $equationtype
566 public function PNGpCALequationTypeLookup($equationtype) {
567 static $PNGpCALequationTypeLookup = array(
568 0 => 'Linear mapping',
569 1 => 'Base-e exponential mapping',
570 2 => 'Arbitrary-base exponential mapping',
571 3 => 'Hyperbolic mapping'
573 return (isset($PNGpCALequationTypeLookup[$equationtype]) ?
$PNGpCALequationTypeLookup[$equationtype] : 'invalid');
581 public function PNGsCALUnitLookup($unitid) {
582 static $PNGsCALUnitLookup = array(
586 return (isset($PNGsCALUnitLookup[$unitid]) ?
$PNGsCALUnitLookup[$unitid] : 'invalid');
590 * @param int $color_type
591 * @param int $bit_depth
595 public function IHDRcalculateBitsPerSample($color_type, $bit_depth) {
596 switch ($color_type) {
597 case 0: // Each pixel is a grayscale sample.
600 case 2: // Each pixel is an R,G,B triple
601 return 3 * $bit_depth;
603 case 3: // Each pixel is a palette index; a PLTE chunk must appear.
606 case 4: // Each pixel is a grayscale sample, followed by an alpha sample.
607 return 2 * $bit_depth;
609 case 6: // Each pixel is an R,G,B triple, followed by an alpha sample.
610 return 4 * $bit_depth;