📄 jpeg.php
字号:
// how much to read, as it won't work for files being read by http or ftp // So instead read 1Mb at a time till EOF $compressed_data = ""; do { $compressed_data .= network_safe_fread( $filehnd, 1048576 ); } while( ! feof( $filehnd ) ); // Strip off EOI and anything after $EOI_pos = strpos( $compressed_data, "\xFF\xD9" ); $compressed_data = substr( $compressed_data, 0, $EOI_pos ); } else { // Not an SOS - Read the next two bytes - should be the segment marker for the next segment $data = network_safe_fread( $filehnd, 2 ); // Check that the first byte of the two is 0xFF as it should be for a marker if ( $data{0} != "\xFF" ) { // Problem - NO FF foundclose file and return"; fclose($filehnd); return; } } } // Close File fclose($filehnd); // Alow the user to abort from now on ignore_user_abort(false); // Return the compressed data if it was found if ( $hit_compressed_image_data ) { return $compressed_data; } else { return FALSE; }}/******************************************************************************* End of Function: get_jpeg_image_data******************************************************************************//******************************************************************************** Function: Generate_JPEG_APP_Segment_HTML** Description: Generates html showing information about the Application (APP)* segments which are present in the JPEG file** Parameters: jpeg_header_data - the JPEG header data, as retrieved* from the get_jpeg_header_data function** Returns: output - A string containing the HTML*******************************************************************************/function Generate_JPEG_APP_Segment_HTML( $jpeg_header_data ){ if ( $jpeg_header_data == FALSE ) { return ""; } // Write Heading $output = "<h2 class=\"JPEG_APP_Segments_Main_Heading\">Application Metadata Segments</h2>\n"; // Create table $output .= "<table class=\"JPEG_APP_Segments_Table\" border=1>\n"; // Cycle through each segment in the array foreach( $jpeg_header_data as $jpeg_header ) { // Check if the segment is a APP segment if ( ( $jpeg_header['SegType'] >= 0xE0 ) && ( $jpeg_header['SegType'] <= 0xEF ) ) { // This is an APP segment // Read APP Segment Name - a Null terminated string at the start of the segment $seg_name = strtok($jpeg_header['SegData'], "\x00"); // Some Segment names are either too long or not meaningfull, so // we should clean them up if ( $seg_name == "http://ns.adobe.com/xap/1.0/" ) { $seg_name = "XAP/RDF (\"http://ns.adobe.com/xap/1.0/\")"; } elseif ( $seg_name == "Photoshop 3.0" ) { $seg_name = "Photoshop IRB (\"Photoshop 3.0\")"; } elseif ( ( strncmp ( $seg_name, "[picture info]", 14) == 0 ) || ( strncmp ( $seg_name, "\x0a\x09\x09\x09\x09[picture info]", 19) == 0 ) ) { $seg_name = "[picture info]"; } elseif ( strncmp ( $seg_name, "Type=", 5) == 0 ) { $seg_name = "Epson Info"; } elseif ( ( strncmp ( $seg_name, "HHHHHHHHHHHHHHH", 15) == 0 ) || ( strncmp ( $seg_name, "@s33", 5) == 0 ) ) { $seg_name = "HP segment full of \"HHHHH\""; } // Clean the segment name so it doesn't cause problems with HTML $seg_name = htmlentities( $seg_name ); // Output a Table row containing this APP segment $output .= "<tr class=\"JPEG_APP_Segments_Table_Row\"><td class=\"JPEG_APP_Segments_Caption_Cell\">$seg_name</td><td class=\"JPEG_APP_Segments_Type_Cell\">" . $jpeg_header['SegName'] . "</td><td class=\"JPEG_APP_Segments_Size_Cell\" align=\"right\">" . strlen( $jpeg_header['SegData']). " bytes</td></tr>\n"; } } // Close the table $output .= "</table>\n"; // Return the HTML return $output;}/******************************************************************************* End of Function: Generate_JPEG_APP_Segment_HTML******************************************************************************//******************************************************************************** Function: network_safe_fread** Description: Retrieves data from a file. This function is required since* the fread function will not always return the requested number* of characters when reading from a network stream or pipe** Parameters: file_handle - the handle of a file to read from* length - the number of bytes requested** Returns: data - the data read from the file. may be less than the number* requested if EOF was hit*******************************************************************************/function network_safe_fread( $file_handle, $length ){ // Create blank string to receive data $data = ""; // Keep reading data from the file until either EOF occurs or we have // retrieved the requested number of bytes while ( ( !feof( $file_handle ) ) && ( strlen($data) < $length ) ) { $data .= fread( $file_handle, $length-strlen($data) ); } // return the data read return $data;}/******************************************************************************* End of Function: network_safe_fread******************************************************************************//******************************************************************************* Global Variable: JPEG_Segment_Names** Contents: The names of the JPEG segment markers, indexed by their marker number*******************************************************************************/$GLOBALS[ "JPEG_Segment_Names" ] = array(0xC0 => "SOF0", 0xC1 => "SOF1", 0xC2 => "SOF2", 0xC3 => "SOF4",0xC5 => "SOF5", 0xC6 => "SOF6", 0xC7 => "SOF7", 0xC8 => "JPG",0xC9 => "SOF9", 0xCA => "SOF10", 0xCB => "SOF11", 0xCD => "SOF13",0xCE => "SOF14", 0xCF => "SOF15",0xC4 => "DHT", 0xCC => "DAC",0xD0 => "RST0", 0xD1 => "RST1", 0xD2 => "RST2", 0xD3 => "RST3",0xD4 => "RST4", 0xD5 => "RST5", 0xD6 => "RST6", 0xD7 => "RST7",0xD8 => "SOI", 0xD9 => "EOI", 0xDA => "SOS", 0xDB => "DQT",0xDC => "DNL", 0xDD => "DRI", 0xDE => "DHP", 0xDF => "EXP",0xE0 => "APP0", 0xE1 => "APP1", 0xE2 => "APP2", 0xE3 => "APP3",0xE4 => "APP4", 0xE5 => "APP5", 0xE6 => "APP6", 0xE7 => "APP7",0xE8 => "APP8", 0xE9 => "APP9", 0xEA => "APP10", 0xEB => "APP11",0xEC => "APP12", 0xED => "APP13", 0xEE => "APP14", 0xEF => "APP15",0xF0 => "JPG0", 0xF1 => "JPG1", 0xF2 => "JPG2", 0xF3 => "JPG3",0xF4 => "JPG4", 0xF5 => "JPG5", 0xF6 => "JPG6", 0xF7 => "JPG7",0xF8 => "JPG8", 0xF9 => "JPG9", 0xFA => "JPG10", 0xFB => "JPG11",0xFC => "JPG12", 0xFD => "JPG13",0xFE => "COM", 0x01 => "TEM", 0x02 => "RES",);/******************************************************************************* End of Global Variable: JPEG_Segment_Names******************************************************************************//******************************************************************************* Global Variable: JPEG_Segment_Descriptions** Contents: The descriptions of the JPEG segment markers, indexed by their marker number*******************************************************************************/$GLOBALS[ "JPEG_Segment_Descriptions" ] = array(/* JIF Marker byte pairs in JPEG Interchange Format sequence */0xC0 => "Start Of Frame (SOF) Huffman - Baseline DCT",0xC1 => "Start Of Frame (SOF) Huffman - Extended sequential DCT",0xC2 => "Start Of Frame Huffman - Progressive DCT (SOF2)",0xC3 => "Start Of Frame Huffman - Spatial (sequential) lossless (SOF3)",0xC5 => "Start Of Frame Huffman - Differential sequential DCT (SOF5)",0xC6 => "Start Of Frame Huffman - Differential progressive DCT (SOF6)",0xC7 => "Start Of Frame Huffman - Differential spatial (SOF7)",0xC8 => "Start Of Frame Arithmetic - Reserved for JPEG extensions (JPG)",0xC9 => "Start Of Frame Arithmetic - Extended sequential DCT (SOF9)",0xCA => "Start Of Frame Arithmetic - Progressive DCT (SOF10)",0xCB => "Start Of Frame Arithmetic - Spatial (sequential) lossless (SOF11)",0xCD => "Start Of Frame Arithmetic - Differential sequential DCT (SOF13)",0xCE => "Start Of Frame Arithmetic - Differential progressive DCT (SOF14)",0xCF => "Start Of Frame Arithmetic - Differential spatial (SOF15)",0xC4 => "Define Huffman Table(s) (DHT)",0xCC => "Define Arithmetic coding conditioning(s) (DAC)",0xD0 => "Restart with modulo 8 count 0 (RST0)",0xD1 => "Restart with modulo 8 count 1 (RST1)",0xD2 => "Restart with modulo 8 count 2 (RST2)",0xD3 => "Restart with modulo 8 count 3 (RST3)",0xD4 => "Restart with modulo 8 count 4 (RST4)",0xD5 => "Restart with modulo 8 count 5 (RST5)",0xD6 => "Restart with modulo 8 count 6 (RST6)",0xD7 => "Restart with modulo 8 count 7 (RST7)",0xD8 => "Start of Image (SOI)",0xD9 => "End of Image (EOI)",0xDA => "Start of Scan (SOS)",0xDB => "Define quantization Table(s) (DQT)",0xDC => "Define Number of Lines (DNL)",0xDD => "Define Restart Interval (DRI)",0xDE => "Define Hierarchical progression (DHP)",0xDF => "Expand Reference Component(s) (EXP)",0xE0 => "Application Field 0 (APP0) - usually JFIF or JFXX",0xE1 => "Application Field 1 (APP1) - usually EXIF or XMP/RDF",0xE2 => "Application Field 2 (APP2) - usually Flashpix",0xE3 => "Application Field 3 (APP3)",0xE4 => "Application Field 4 (APP4)",0xE5 => "Application Field 5 (APP5)",0xE6 => "Application Field 6 (APP6)",0xE7 => "Application Field 7 (APP7)",0xE8 => "Application Field 8 (APP8)",0xE9 => "Application Field 9 (APP9)",0xEA => "Application Field 10 (APP10)",0xEB => "Application Field 11 (APP11)",0xEC => "Application Field 12 (APP12) - usually [picture info]",0xED => "Application Field 13 (APP13) - usually photoshop IRB / IPTC",0xEE => "Application Field 14 (APP14)",0xEF => "Application Field 15 (APP15)",0xF0 => "Reserved for JPEG extensions (JPG0)",0xF1 => "Reserved for JPEG extensions (JPG1)",0xF2 => "Reserved for JPEG extensions (JPG2)",0xF3 => "Reserved for JPEG extensions (JPG3)",0xF4 => "Reserved for JPEG extensions (JPG4)",0xF5 => "Reserved for JPEG extensions (JPG5)",0xF6 => "Reserved for JPEG extensions (JPG6)",0xF7 => "Reserved for JPEG extensions (JPG7)",0xF8 => "Reserved for JPEG extensions (JPG8)",0xF9 => "Reserved for JPEG extensions (JPG9)",0xFA => "Reserved for JPEG extensions (JPG10)",0xFB => "Reserved for JPEG extensions (JPG11)",0xFC => "Reserved for JPEG extensions (JPG12)",0xFD => "Reserved for JPEG extensions (JPG13)",0xFE => "Comment (COM)",0x01 => "For temp private use arith code (TEM)",0x02 => "Reserved (RES)",);/******************************************************************************* End of Global Variable: JPEG_Segment_Descriptions******************************************************************************/?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -