📄 jfif.php
字号:
/******************************************************************************* End of Function: Interpret_JFIF_to_HTML******************************************************************************//******************************************************************************** Function: get_JFXX** Description: Retrieves information from a JPEG File Interchange Format Extension (JFXX)* segment and returns it in an array. Uses information supplied by* the get_jpeg_header_data function** Parameters: jpeg_header_data - a JPEG header data array in the same format* as from get_jpeg_header_data** Returns: JFXX_data - an array of JFXX data* FALSE - if a JFXX segment could not be found*******************************************************************************/function get_JFXX( $jpeg_header_data ){ //Cycle through the header segments for( $i = 0; $i < count( $jpeg_header_data ); $i++ ) { // If we find an APP0 header, if ( strcmp ( $jpeg_header_data[$i]['SegName'], "APP0" ) == 0 ) { // And if it has the JFIF label, if( strncmp ( $jpeg_header_data[$i]['SegData'], "JFXX\x00", 5) == 0 ) { // Found a JPEG File Interchange Format Extension (JFXX) Block // unpack the JFXX data from the incoming string // First is the 5 byte JFXX label string // Then a 1 byte Extension code, indicating Thumbnail Format // Then the thumbnail data $JFXX_data = unpack( 'a5JFXX/CExtension_Code/a*ThumbData', $jpeg_header_data[$i]['SegData'] ); return $JFXX_data; } } } return FALSE;}/******************************************************************************* End of Function: get_JFXX******************************************************************************//******************************************************************************** Function: put_JFXX** Description: Creates a new JFXX segment from an array of JFXX data in the* same format as would be retrieved from get_JFXX, and inserts* this segment into the supplied JPEG header array** Parameters: jpeg_header_data - a JPEG header data array in the same format* as from get_jpeg_header_data, into which the* new JFXX segment will be put* new_JFXX_array - a JFXX information array in the same format as* from get_JFXX, to create the new segment** Returns: jpeg_header_data - the JPEG header data array with the new* JFXX segment added*******************************************************************************/function put_JFXX( $jpeg_header_data, $new_JFXX_array ){ // pack the JFXX data into its proper format for a JPEG file $packed_data = pack( 'a5Ca*',"JFXX\x00", $new_JFXX_array['Extension_Code'], $new_JFXX_array['ThumbData'] ); $JFIF_pos = -1; //Cycle through the header segments for( $i = 0; $i < count( $jpeg_header_data ); $i++ ) { // If we find an APP0 header, if ( strcmp ( $jpeg_header_data[$i]['SegName'], "APP0" ) == 0 ) { // And if it has the JFXX label, if( strncmp ( $jpeg_header_data[$i]['SegData'], "JFXX\x00", 5) == 0 ) { // Found a preexisting JFXX block - Replace it with the new one and return. $jpeg_header_data[$i]['SegData'] = $packed_data; return $jpeg_header_data; } // if it has the JFIF label, if( strncmp ( $jpeg_header_data[$i][SegData], "JFIF\x00", 5) == 0 ) { // Found a preexisting JFIF block - Mark it in case we need to insert the JFXX after it $JFIF_pos = $i; } } } // No preexisting JFXX block found // Check if a JFIF segment was found, if ( $JFIF_pos !== -1 ) { // A pre-existing JFIF segment was found, // insert the new JFXX segment after it. array_splice($jpeg_header_data, $JFIF_pos +1 , 0, array ( array( "SegType" => 0xE0, "SegName" => "APP0", "SegDesc" => $GLOBALS[ "JPEG_Segment_Descriptions" ][ 0xE0 ], "SegData" => $packed_data ) ) ); } else { // No pre-existing JFIF segment was found, // insert a new JFIF and the new JFXX segment at the start of the array. // Insert new JFXX segment array_splice($jpeg_header_data, 0 , 0, array( array( "SegType" => 0xE0, "SegName" => "APP0", "SegDesc" => $GLOBALS[ "JPEG_Segment_Descriptions" ][ 0xE0 ], "SegData" => $packed_data ) ) ); // Create a new JFIF to be inserted at the start of // the array, with generic values $packed_data = pack( 'a5CCCnnCCa*',"JFIF\x00", 1, 2, 1, 72, 72, 0, 0, "" ); array_splice($jpeg_header_data, 0 , 0, array( array( "SegType" => 0xE0, "SegName" => "APP0", "SegDesc" => $GLOBALS[ "JPEG_Segment_Descriptions" ][ 0xE0 ], "SegData" => $packed_data ) ) ); } return $jpeg_header_data;}/******************************************************************************* End of Function: put_JFIF******************************************************************************//******************************************************************************** Function: Interpret_JFXX_to_HTML** Description: Generates html showing the JFXX thumbnail contained in* a JFXX data array, as retrieved with get_JFXX** Parameters: JFXX_array - a JFXX information array in the same format as* from get_JFXX, to create the new segment* filename - the name of the JPEG file being processed ( used* by the script which displays the JFXX thumbnail)** Returns: output - the Html string*******************************************************************************/function Interpret_JFXX_to_HTML( $JFXX_array, $filename ){ $output = ""; if ( $JFXX_array !== FALSE ) { $output .= "<H2 class=\"JFXX_Main_Heading\">Contains JPEG File Interchange Extension Format (JFXX) Thumbnail</H2>\n"; switch ( $JFXX_array['Extension_Code'] ) { case 0x10 : $output .= "<p class=\"JFXX_Text\">JFXX Thumbnail is JPEG Encoded</p>\n"; // Change: as of version 1.11 - Changed to make thumbnail link portable across directories // Build the path of the thumbnail script and its filename parameter to put in a url $link_str = get_relative_path( dirname(__FILE__) . "/get_JFXX_thumb.php" , getcwd ( ) ); $link_str .= "?filename="; $link_str .= get_relative_path( $filename, dirname(__FILE__) ); // Add thumbnail link to html $output .= "<a class=\"JFXX_Thumbnail_Link\" href=\"$link_str\"><img class=\"JFXX_Thumbnail\" src=\"$link_str\"></a>\n"; break; case 0x11 : $output .= "<p class=\"JFXX_Text\">JFXX Thumbnail is Encoded 1 byte/pixel</p>\n"; $output .= "<p class=\"JFXX_Text\">Thumbnail Display Not Implemented Yet</p>\n"; break; case 0x13 : $output .= "<p class=\"JFXX_Text\">JFXX Thumbnail is Encoded 3 bytes/pixel</p>\n"; $output .= "<p class=\"JFXX_Text\">Thumbnail Display Not Implemented Yet</p>\n"; break; default : $output .= "<p class=\"JFXX_Text\">JFXX Thumbnail is Encoded with Unknown format</p>\n"; break; // TODO: Implement JFXX one and three bytes per pixel thumbnail decoding } } return $output;}/******************************************************************************* End of Function: Interpret_JFXX_to_HTML******************************************************************************/?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -