0xE0, "SegName" => "APP0", "SegDesc" => $GLOBALS[ "JPEG_Segment_Descriptions" ][ 0xE0 ], "SegData" => $packed_data ) ) ); return $jpeg_header_data; } /****************************************************************************** * End of Function: put_JFIF ******************************************************************************/ /****************************************************************************** * * Function: Interpret_JFIF_to_HTML * * Description: Generates html showing the JFIF information contained in * a JFIF data array, as retrieved with get_JFIF * * Parameters: JFIF_array - a JFIF data array, as from get_JFIF * filename - the name of the JPEG file being processed ( used * by the script which displays the JFIF thumbnail) * * * Returns: output - the HTML string * ******************************************************************************/ function Interpret_JFIF_to_HTML( $JFIF_array, $filename ) { $output = ""; if ( $JFIF_array !== FALSE ) { $output .= "

Contains JPEG File Interchange Format (JFIF) Information

\n"; $output .= "\n\n"; $output .= "\n"; if ( $JFIF_array['Units'] == 0 ) { $output .= "\n"; } elseif ( $JFIF_array['Units'] == 1 ) { $output .= "\n"; } elseif ( $JFIF_array['Units'] == 2 ) { $output .= "\n"; } $output .= "\n"; // TODO Implement JFIF Thumbnail display } else { $output .= "None\n"; } $output .= "
JFIF version: ". sprintf( "%d.%02d", $JFIF_array['Version1'], $JFIF_array['Version2'] ) . "
Pixel Aspect Ratio: " . $JFIF_array['XDensity'] ." x " . $JFIF_array['YDensity'] . "
Resolution: " . $JFIF_array['XDensity'] ." x " . $JFIF_array['YDensity'] . " pixels per inch
Resolution: " . $JFIF_array['XDensity'] ." x " . $JFIF_array['YDensity'] . " pixels per cm
JFIF (uncompressed) thumbnail: "; if ( ( $JFIF_array['ThumbX'] != 0 ) && ( $JFIF_array['ThumbY'] != 0 ) ) { $output .= $JFIF_array['ThumbX'] ." x " . $JFIF_array['ThumbY'] . " pixels, Thumbnail Display Not Yet Implemented

\n"; } return $output; } /****************************************************************************** * 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 .= "

Contains JPEG File Interchange Extension Format (JFXX) Thumbnail

\n"; switch ( $JFXX_array['Extension_Code'] ) { case 0x10 : $output .= "

JFXX Thumbnail is JPEG Encoded

\n"; $output .= "\n"; break; case 0x11 : $output .= "

JFXX Thumbnail is Encoded 1 byte/pixel

\n"; $output .= "

Thumbnail Display Not Implemented Yet

\n"; break; case 0x13 : $output .= "

JFXX Thumbnail is Encoded 3 bytes/pixel

\n"; $output .= "

Thumbnail Display Not Implemented Yet

\n"; break; default : $output .= "

JFXX Thumbnail is Encoded with Unknown format

\n"; break; // TODO: Implement JFXX one and three bytes per pixel thumbnail decoding } } return $output; } /****************************************************************************** * End of Function: Interpret_JFXX_to_HTML ******************************************************************************/ ?>