$App12_PI_Head, "Picture Info" => substr( $App12_PI_Text, 0, $pos + 5 ) ); } else { return array( "Header" => $App12_PI_Head, "Picture Info" => $App12_PI_Text ); } } // No Picture Info Segment Found - Return False return array( FALSE, FALSE ); } /****************************************************************************** * End of Function: get_jpeg_header_data ******************************************************************************/ /****************************************************************************** * * Function: put_jpeg_App12_Pic_Info * * Description: Writes Picture Info text into an App12 JPEG segment. Uses information * supplied by the get_jpeg_header_data function. If no App12 exists * already a new one is created, otherwise it replaces the old one * * Parameters: jpeg_header_data - a JPEG header data array in the same format * as from get_jpeg_header_data * new_Pic_Info_Text - The Picture Info Text, including any header * that is required * * Returns: jpeg_header_data - the JPEG header array with the new Picture * info segment inserted * FALSE - if an error occured * ******************************************************************************/ function put_jpeg_App12_Pic_Info( $jpeg_header_data, $new_Pic_Info_Text ) { //Cycle through the header segments for( $i = 0; $i < count( $jpeg_header_data ); $i++ ) { // Check if we have found an APP12 header, if ( strcmp ( $jpeg_header_data[$i][SegName], "APP12" ) == 0 ) { // Found an APP12 segment // Check if the APP12 has one of the correct labels (headers) // for a picture info segment if ( ( strncmp ( $jpeg_header_data[$i]['SegData'], "[picture info]", 14) == 0 ) || ( strncmp ( $jpeg_header_data[$i]['SegData'], "\x0a\x09\x09\x09\x09[picture info]", 19) == 0 ) || ( strncmp ( $jpeg_header_data[$i]['SegData'], "SEIKO EPSON CORP. \x00", 20) == 0 ) || ( strncmp ( $jpeg_header_data[$i]['SegData'], "Agfa Gevaert \x00", 16) == 0 ) || ( strncmp ( $jpeg_header_data[$i]['SegData'], "SanyoElectricDSC\x00", 17) == 0 ) || ( strncmp ( $jpeg_header_data[$i]['SegData'], "Type=", 5) == 0 ) || ( strncmp ( $jpeg_header_data[$i]['SegData'], "OLYMPUS OPTICAL CO.,LTD.", 24) == 0 ) ) { // Found a preexisting Picture Info segment - Replace it with the new one and return. $jpeg_header_data[$i][SegData] = $new_Pic_Info_Text; return $jpeg_header_data; } } } // No preexisting Picture Info segment found, insert a new one at the start of the header data. // Determine highest position of an APP segment at or below APP12, so we can put the // new APP12 at this position $highest_APP = -1; //Cycle through the header segments for( $i = 0; $i < count( $jpeg_header_data ); $i++ ) { // Check if we have found an APP segment at or below APP12, if ( ( $jpeg_header_data[$i]['SegType'] >= 0xE0 ) && ( $jpeg_header_data[$i]['SegType'] <= 0xEC ) ) { // Found an APP segment at or below APP12 $highest_APP = $i; } } // Insert the new Picture Info segment array_splice($jpeg_header_data, $highest_APP + 1 , 0, array( array( "SegType" => 0xEC, "SegName" => "APP12", "SegDesc" => $GLOBALS[ "JPEG_Segment_Descriptions" ][ 0xEC ], "SegData" => $new_Pic_Info_Text ) ) ); return $jpeg_header_data; } /****************************************************************************** * End of Function: put_jpeg_header_data ******************************************************************************/ /****************************************************************************** * * Function: Interpret_App12_Pic_Info_to_HTML * * Description: Generates html showing the contents of any JPEG App12 Picture * Info segment * * Parameters: jpeg_header_data - the JPEG header data, as retrieved * from the get_jpeg_header_data function * * Returns: output - the HTML * ******************************************************************************/ function Interpret_App12_Pic_Info_to_HTML( $jpeg_header_data ) { // Create a string to receive the output $output = ""; // read the App12 Picture Info segment $PI = get_jpeg_App12_Pic_Info( $jpeg_header_data ); // Check if the Picture Info segment was valid if ( $PI !== array(FALSE, FALSE) ) { // Picture Info exists - add it to the output $output .= "

Picture Info Text

\n"; $output .= "

Header: " . HTML_UTF8_Escape( $PI['Header'] ) . "

\n"; $output .= "

Picture Info Text:

" . HTML_UTF8_Escape( $PI['Picture Info'] ) . "
\n"; } // Return the result return $output; } /****************************************************************************** * End of Function: Interpret_App12_Pic_Info_to_HTML ******************************************************************************/ ?>