⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module.graphic.png.php

📁 一个用PHP编写的
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php//////////////////////////////////////////////////////////////////// getID3() by James Heinrich <info@getid3.org>               ////  available at http://getid3.sourceforge.net                 ////            or http://www.getid3.org                         ///////////////////////////////////////////////////////////////////// See readme.txt for more details                             /////////////////////////////////////////////////////////////////////                                                             //// module.graphic.png.php                                      //// module for analyzing PNG Image files                        //// dependencies: NONE                                          ////                                                            ////////////////////////////////////////////////////////////////////class getid3_png{	function getid3_png(&$fd, &$ThisFileInfo) {	    // shortcut	    $ThisFileInfo['png'] = array();	    $thisfile_png = &$ThisFileInfo['png'];		$ThisFileInfo['fileformat']          = 'png';		$ThisFileInfo['video']['dataformat'] = 'png';		$ThisFileInfo['video']['lossless']   = false;		fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);		$PNGfiledata = fread($fd, GETID3_FREAD_BUFFER_SIZE);		$offset = 0;		$PNGidentifier = substr($PNGfiledata, $offset, 8); // $89 $50 $4E $47 $0D $0A $1A $0A		$offset += 8;		if ($PNGidentifier != "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") {			$ThisFileInfo['error'][] = 'First 8 bytes of file ('.getid3_lib::PrintHexBytes($PNGidentifier).') did not match expected PNG identifier';			unset($ThisFileInfo['fileformat']);			return false;		}		while (((ftell($fd) - (strlen($PNGfiledata) - $offset)) < $ThisFileInfo['filesize'])) {			$chunk['data_length'] = getid3_lib::BigEndian2Int(substr($PNGfiledata, $offset, 4));			$offset += 4;			while (((strlen($PNGfiledata) - $offset) < ($chunk['data_length'] + 4)) && (ftell($fd) < $ThisFileInfo['filesize'])) {				$PNGfiledata .= fread($fd, GETID3_FREAD_BUFFER_SIZE);			}			$chunk['type_text']   =               substr($PNGfiledata, $offset, 4);			$offset += 4;			$chunk['type_raw']    = getid3_lib::BigEndian2Int($chunk['type_text']);			$chunk['data']        =               substr($PNGfiledata, $offset, $chunk['data_length']);			$offset += $chunk['data_length'];			$chunk['crc']         = getid3_lib::BigEndian2Int(substr($PNGfiledata, $offset, 4));			$offset += 4;			$chunk['flags']['ancilliary']   = (bool) ($chunk['type_raw'] & 0x20000000);			$chunk['flags']['private']      = (bool) ($chunk['type_raw'] & 0x00200000);			$chunk['flags']['reserved']     = (bool) ($chunk['type_raw'] & 0x00002000);			$chunk['flags']['safe_to_copy'] = (bool) ($chunk['type_raw'] & 0x00000020);			// shortcut			$thisfile_png[$chunk['type_text']] = array();			$thisfile_png_chunk_type_text = &$thisfile_png[$chunk['type_text']];			switch ($chunk['type_text']) {				case 'IHDR': // Image Header					$thisfile_png_chunk_type_text['header'] = $chunk;					$thisfile_png_chunk_type_text['width']                     = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'],  0, 4));					$thisfile_png_chunk_type_text['height']                    = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'],  4, 4));					$thisfile_png_chunk_type_text['raw']['bit_depth']          = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'],  8, 1));					$thisfile_png_chunk_type_text['raw']['color_type']         = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'],  9, 1));					$thisfile_png_chunk_type_text['raw']['compression_method'] = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], 10, 1));					$thisfile_png_chunk_type_text['raw']['filter_method']      = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], 11, 1));					$thisfile_png_chunk_type_text['raw']['interlace_method']   = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], 12, 1));					$thisfile_png_chunk_type_text['compression_method_text']   = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['raw']['compression_method']);					$thisfile_png_chunk_type_text['color_type']['palette']     = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x01);					$thisfile_png_chunk_type_text['color_type']['true_color']  = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x02);					$thisfile_png_chunk_type_text['color_type']['alpha']       = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x04);					$ThisFileInfo['video']['resolution_x']    = $thisfile_png_chunk_type_text['width'];					$ThisFileInfo['video']['resolution_y']    = $thisfile_png_chunk_type_text['height'];					$ThisFileInfo['video']['bits_per_sample'] = $this->IHDRcalculateBitsPerSample($thisfile_png_chunk_type_text['raw']['color_type'], $thisfile_png_chunk_type_text['raw']['bit_depth']);					break;				case 'PLTE': // Palette					$thisfile_png_chunk_type_text['header'] = $chunk;					$paletteoffset = 0;					for ($i = 0; $i <= 255; $i++) {						//$thisfile_png_chunk_type_text['red'][$i]   = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], $paletteoffset++, 1));						//$thisfile_png_chunk_type_text['green'][$i] = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], $paletteoffset++, 1));						//$thisfile_png_chunk_type_text['blue'][$i]  = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], $paletteoffset++, 1));						$red   = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], $paletteoffset++, 1));						$green = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], $paletteoffset++, 1));						$blue  = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], $paletteoffset++, 1));						$thisfile_png_chunk_type_text[$i] = (($red << 16) | ($green << 8) | ($blue));					}					break;				case 'tRNS': // Transparency					$thisfile_png_chunk_type_text['header'] = $chunk;					switch ($thisfile_png['IHDR']['raw']['color_type']) {						case 0:							$thisfile_png_chunk_type_text['transparent_color_gray']  = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], 0, 2));							break;						case 2:							$thisfile_png_chunk_type_text['transparent_color_red']   = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], 0, 2));							$thisfile_png_chunk_type_text['transparent_color_green'] = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], 2, 2));							$thisfile_png_chunk_type_text['transparent_color_blue']  = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], 4, 2));							break;						case 3:							for ($i = 0; $i < strlen($thisfile_png_chunk_type_text['header']['data']); $i++) {								$thisfile_png_chunk_type_text['palette_opacity'][$i] = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], $i, 1));							}							break;						case 4:						case 6:							$ThisFileInfo['error'][] = 'Invalid color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type'];						default:							$ThisFileInfo['warning'][] = 'Unhandled color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type'];							break;					}					break;				case 'gAMA': // Image Gamma					$thisfile_png_chunk_type_text['header'] = $chunk;					$thisfile_png_chunk_type_text['gamma']  = getid3_lib::BigEndian2Int($thisfile_png_chunk_type_text['header']['data']) / 100000;					break;				case 'cHRM': // Primary Chromaticities					$thisfile_png_chunk_type_text['header']  = $chunk;					$thisfile_png_chunk_type_text['white_x'] = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'],  0, 4)) / 100000;					$thisfile_png_chunk_type_text['white_y'] = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'],  4, 4)) / 100000;					$thisfile_png_chunk_type_text['red_y']   = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'],  8, 4)) / 100000;					$thisfile_png_chunk_type_text['red_y']   = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], 12, 4)) / 100000;					$thisfile_png_chunk_type_text['green_y'] = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], 16, 4)) / 100000;					$thisfile_png_chunk_type_text['green_y'] = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], 20, 4)) / 100000;					$thisfile_png_chunk_type_text['blue_y']  = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], 24, 4)) / 100000;					$thisfile_png_chunk_type_text['blue_y']  = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], 28, 4)) / 100000;					break;				case 'sRGB': // Standard RGB Color Space					$thisfile_png_chunk_type_text['header']                 = $chunk;					$thisfile_png_chunk_type_text['reindering_intent']      = getid3_lib::BigEndian2Int($thisfile_png_chunk_type_text['header']['data']);					$thisfile_png_chunk_type_text['reindering_intent_text'] = $this->PNGsRGBintentLookup($thisfile_png_chunk_type_text['reindering_intent']);					break;				case 'iCCP': // Embedded ICC Profile					$thisfile_png_chunk_type_text['header']                  = $chunk;					list($profilename, $compressiondata)                                 = explode("\x00", $thisfile_png_chunk_type_text['header']['data'], 2);					$thisfile_png_chunk_type_text['profile_name']            = $profilename;					$thisfile_png_chunk_type_text['compression_method']      = getid3_lib::BigEndian2Int(substr($compressiondata, 0, 1));					$thisfile_png_chunk_type_text['compression_profile']     = substr($compressiondata, 1);					$thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']);					break;				case 'tEXt': // Textual Data					$thisfile_png_chunk_type_text['header']  = $chunk;					list($keyword, $text)                                = explode("\x00", $thisfile_png_chunk_type_text['header']['data'], 2);					$thisfile_png_chunk_type_text['keyword'] = $keyword;					$thisfile_png_chunk_type_text['text']    = $text;					$thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text'];					break;				case 'zTXt': // Compressed Textual Data					$thisfile_png_chunk_type_text['header']                  = $chunk;					list($keyword, $otherdata)                                           = explode("\x00", $thisfile_png_chunk_type_text['header']['data'], 2);					$thisfile_png_chunk_type_text['keyword']                 = $keyword;					$thisfile_png_chunk_type_text['compression_method']      = getid3_lib::BigEndian2Int(substr($otherdata, 0, 1));					$thisfile_png_chunk_type_text['compressed_text']         = substr($otherdata, 1);					$thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']);					switch ($thisfile_png_chunk_type_text['compression_method']) {						case 0:							$thisfile_png_chunk_type_text['text']            = gzuncompress($thisfile_png_chunk_type_text['compressed_text']);							break;						default:							// unknown compression method							break;					}					if (isset($thisfile_png_chunk_type_text['text'])) {						$thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text'];					}					break;				case 'iTXt': // International Textual Data					$thisfile_png_chunk_type_text['header']                  = $chunk;					list($keyword, $otherdata)                                           = explode("\x00", $thisfile_png_chunk_type_text['header']['data'], 2);					$thisfile_png_chunk_type_text['keyword']                 = $keyword;					$thisfile_png_chunk_type_text['compression']             = (bool) getid3_lib::BigEndian2Int(substr($otherdata, 0, 1));					$thisfile_png_chunk_type_text['compression_method']      = getid3_lib::BigEndian2Int(substr($otherdata, 1, 1));					$thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']);					list($languagetag, $translatedkeyword, $text)                        = explode("\x00", substr($otherdata, 2), 3);					$thisfile_png_chunk_type_text['language_tag']            = $languagetag;					$thisfile_png_chunk_type_text['translated_keyword']      = $translatedkeyword;					if ($thisfile_png_chunk_type_text['compression']) {						switch ($thisfile_png_chunk_type_text['compression_method']) {							case 0:								$thisfile_png_chunk_type_text['text']        = gzuncompress($text);								break;							default:								// unknown compression method								break;						}					} else {						$thisfile_png_chunk_type_text['text']                = $text;					}					if (isset($thisfile_png_chunk_type_text['text'])) {						$thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text'];					}					break;				case 'bKGD': // Background Color					$thisfile_png_chunk_type_text['header']                   = $chunk;					switch ($thisfile_png['IHDR']['raw']['color_type']) {						case 0:						case 4:							$thisfile_png_chunk_type_text['background_gray']  = getid3_lib::BigEndian2Int($thisfile_png_chunk_type_text['header']['data']);							break;						case 2:						case 6:							$thisfile_png_chunk_type_text['background_red']   = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], 0 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth']));							$thisfile_png_chunk_type_text['background_green'] = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], 1 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth']));							$thisfile_png_chunk_type_text['background_blue']  = getid3_lib::BigEndian2Int(substr($thisfile_png_chunk_type_text['header']['data'], 2 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth']));							break;						case 3:							$thisfile_png_chunk_type_text['background_index'] = getid3_lib::BigEndian2Int($thisfile_png_chunk_type_text['header']['data']);							break;						default:							break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -