/****************************************************************************** * * Filename: Photoshop_IRB.php * * Description: Provides functions for reading and writing information to/from * the 'App 13' Photoshop Information Resource Block segment of * JPEG format files * * Author: Evan Hunter * * Date: 23/7/2004 * * Project: PHP JPEG Metadata Toolkit * * Revision: 1.11 * * Changes: 1.00 -> 1.02 : changed get_Photoshop_IRB to work with corrupted * resource names which Photoshop can still read * 1.02 -> 1.03 : Fixed put_Photoshop_IRB to output "Photoshop 3.0\x00" * string with every APP13 segment, not just the first one * 1.03 -> 1.10 : changed get_Photoshop_IRB to fix processing of embedded resource names, * after discovering that Photoshop does not process * resource names according to the standard : * "Adobe Photoshop 6.0 File Formats Specification, Version 6.0, Release 2, November 2000" * This is an update to the change 1.00 -> 1.02, which was not fully correct * changed put_Photoshop_IRB to fix the writing of embedded resource name, * to avoid creating blank resources, and to fix a problem * causing the IRB block to be incorrectly positioned if no APP segments existed. * changed get_Photoshop_IPTC to initialise the output array correctly. * 1.10 -> 1.11 : Moved code out of get_Photoshop_IRB into new function unpack_Photoshop_IRB_Data * to allow reading of IRB blocks embedded within EXIF (for TIFF Files) * Moved code out of put_Photoshop_IRB into new function pack_Photoshop_IRB_Data * to allow writing of IRB blocks embedded within EXIF (for TIFF Files) * Enabled the usage of $GLOBALS['HIDE_UNKNOWN_TAGS'] to hide unknown resources * changed Interpret_IRB_to_HTML to allow thumbnail links to work when * toolkit is portable across directories * * * URL: http://electronics.ozhiker.com * * Copyright: Copyright Evan Hunter 2004 * * License: This file is part of the PHP JPEG Metadata Toolkit. * * The PHP JPEG Metadata Toolkit is free software; you can * redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your * option) any later version. * * The PHP JPEG Metadata Toolkit is distributed in the hope * that it will be useful, but WITHOUT ANY WARRANTY; without * even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public * License along with the PHP JPEG Metadata Toolkit; if not, * write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA * * If you require a different license for commercial or other * purposes, please contact the author: evan@ozhiker.com * ******************************************************************************/ // Change: as of version 1.11 - added to ensure the HIDE_UNKNOWN_TAGS variable is set even if EXIF.php is not included if ( !isset( $GLOBALS['HIDE_UNKNOWN_TAGS'] ) ) $GLOBALS['HIDE_UNKNOWN_TAGS']= FALSE; include_once 'IPTC.php'; include_once 'Unicode.php'; // TODO: Many Photoshop IRB resources not interpeted // TODO: Obtain a copy of the Photoshop CS File Format Specification // TODO: Find out what Photoshop IRB resources 1061, 1062 & 1064 are // TODO: Test get_Photoshop_IRB and put_Photoshop_IRB with multiple APP13 segments /****************************************************************************** * * Function: get_Photoshop_IRB * * Description: Retrieves the Photoshop Information Resource Block (IRB) information * from an App13 JPEG segment and returns it as an array. This may * include IPTC-NAA IIM Information. 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: IRBdata - The array of Photoshop IRB records * FALSE - if an APP 13 Photoshop IRB segment could not be found, * or if an error occured * ******************************************************************************/ function get_Photoshop_IRB( $jpeg_header_data ) { // Photoshop Image Resource blocks can span several JPEG APP13 segments, so we need to join them up if there are more than one $joined_IRB = ""; //Cycle through the header segments for( $i = 0; $i < count( $jpeg_header_data ); $i++ ) { // If we find an APP13 header, if ( strcmp ( $jpeg_header_data[$i]['SegName'], "APP13" ) == 0 ) { // And if it has the photoshop label, if( strncmp ( $jpeg_header_data[$i]['SegData'], "Photoshop 3.0\x00", 14) == 0 ) { // join it to the other previous IRB data $joined_IRB .= substr ( $jpeg_header_data[$i]['SegData'], 14 ); } } } // If there was some Photoshop IRB information found, if ( $joined_IRB != "" ) { // Found a Photoshop Image Resource Block - extract it. // Change: Moved code into unpack_Photoshop_IRB_Data to allow TIFF reading as of 1.11 return unpack_Photoshop_IRB_Data( $joined_IRB ); } else { // No Photoshop IRB found return FALSE; } } /****************************************************************************** * End of Function: get_Photoshop_IRB ******************************************************************************/ /****************************************************************************** * * Function: put_Photoshop_IRB * * Description: Adds or modifies the Photoshop Information Resource Block (IRB) * information from an App13 JPEG segment. If a Photoshop IRB already * exists, it is replaced, otherwise a new one is inserted, using the * supplied data. 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 * new_IRB_data - an array of the data to be stored in the Photoshop * IRB segment. Should be in the same format as received * from get_Photoshop_IRB * * Returns: jpeg_header_data - the JPEG header data array with the * Photoshop IRB added. * FALSE - if an error occured * ******************************************************************************/ function put_Photoshop_IRB( $jpeg_header_data, $new_IRB_data ) { // Delete all existing Photoshop IRB blocks - the new one will replace them //Cycle through the header segments for( $i = 0; $i < count( $jpeg_header_data ) ; $i++ ) { // If we find an APP13 header, if ( strcmp ( $jpeg_header_data[$i]['SegName'], "APP13" ) == 0 ) { // And if it has the photoshop label, if( strncmp ( $jpeg_header_data[$i]['SegData'], "Photoshop 3.0\x00", 14) == 0 ) { // Delete the block information - it needs to be rebuilt array_splice( $jpeg_header_data, $i, 1 ); } } } // Now we have deleted the pre-existing blocks // Retrieve the Packed Photoshop IRB Data // Change: Moved code into pack_Photoshop_IRB_Data to allow TIFF writing as of 1.11 $packed_IRB_data = pack_Photoshop_IRB_Data( $new_IRB_data ); // Change : This section changed to fix incorrect positioning of IRB segment, as of revision 1.10 // when there are no APP segments present //Cycle through the header segments in reverse order (to find where to put the APP13 block - after any APP0 to APP12 blocks) $i = count( $jpeg_header_data ) - 1; while (( $i >= 0 ) && ( ( $jpeg_header_data[$i]['SegType'] > 0xED ) || ( $jpeg_header_data[$i]['SegType'] < 0xE0 ) ) ) { $i--; } // Cycle through the packed output data until it's size is less than 32000 bytes, outputting each 32000 byte block to an APP13 segment while ( strlen( $packed_IRB_data ) > 32000 ) { // Change: Fixed put_Photoshop_IRB to output "Photoshop 3.0\x00" string with every APP13 segment, not just the first one, as of 1.03 // Write a 32000 byte APP13 segment array_splice($jpeg_header_data, $i +1 , 0, array( "SegType" => 0xED, "SegName" => "APP13", "SegDesc" => $GLOBALS[ "JPEG_Segment_Descriptions" ][ 0xED ], "SegData" => "Photoshop 3.0\x00" . substr( $packed_IRB_data,0,32000) ) ); // Delete the 32000 bytes from the packed output data, that were just output $packed_IRB_data = substr_replace($packed_IRB_data, '', 0, 32000); $i++; } // Write the last block of packed output data to an APP13 segment - Note array_splice doesn't work with multidimensional arrays, hence inserting a blank string array_splice($jpeg_header_data, $i + 1 , 0, "" ); $jpeg_header_data[$i + 1] = array( "SegType" => 0xED, "SegName" => "APP13", "SegDesc" => $GLOBALS[ "JPEG_Segment_Descriptions" ][ 0xED ], "SegData" => "Photoshop 3.0\x00" . $packed_IRB_data ); return $jpeg_header_data; } /****************************************************************************** * End of Function: put_Photoshop_IRB ******************************************************************************/ /****************************************************************************** * * Function: get_Photoshop_IPTC * * Description: Retrieves IPTC-NAA IIM information from within a Photoshop * IRB (if it is present) and returns it in an array. Uses * information supplied by the get_jpeg_header_data function * * Parameters: Photoshop_IRB_data - an array of Photoshop IRB records, as * returned from get_Photoshop_IRB * * Returns: IPTC_Data_Out - The array of IPTC-NAA IIM records * FALSE - if an IPTC-NAA IIM record could not be found, or if * an error occured * ******************************************************************************/ function get_Photoshop_IPTC( $Photoshop_IRB_data ) { // Change: Initialise array correctly, as of revision 1.10 $IPTC_Data_Out = array(); //Cycle through the Photoshop 8BIM records looking for the IPTC-NAA record for( $i = 0; $i < count( $Photoshop_IRB_data ); $i++ ) { // Check if each record is a IPTC record (which has id 0x0404) if ( $Photoshop_IRB_data[$i]['ResID'] == 0x0404 ) { // We've found an IPTC block - Decode it $IPTC_Data_Out = get_IPTC( $Photoshop_IRB_data[$i]['ResData'] ); } } // If there was no records put into the output array, if ( count( $IPTC_Data_Out ) == 0 ) { // Then return false return FALSE; } else { // Otherwise return the array return $IPTC_Data_Out; } } /****************************************************************************** * End of Function: get_Photoshop_IPTC ******************************************************************************/ /****************************************************************************** * * Function: put_Photoshop_IPTC * * Description: Inserts a new IPTC-NAA IIM resource into a Photoshop * IRB, or replaces an the existing resource if one is present. * Uses information supplied by the get_Photoshop_IRB function * * Parameters: Photoshop_IRB_data - an array of Photoshop IRB records, as * returned from get_Photoshop_IRB, into * which the IPTC-NAA IIM record will be inserted * new_IPTC_block - an array of IPTC-NAA records in the same format * as those returned by get_Photoshop_IPTC * * Returns: Photoshop_IRB_data - The Photoshop IRB array with the * IPTC-NAA IIM resource inserted * ******************************************************************************/ function put_Photoshop_IPTC( $Photoshop_IRB_data, $new_IPTC_block ) { $iptc_block_pos = -1; //Cycle through the 8BIM records looking for the IPTC-NAA record for( $i = 0; $i < count( $Photoshop_IRB_data ); $i++ ) { // Check if each record is a IPTC record (which has id 0x0404) if ( $Photoshop_IRB_data[$i]['ResID'] == 0x0404 ) { // We've found an IPTC block - save the position $iptc_block_pos = $i; } } // If no IPTC block was found, create a new one if ( $iptc_block_pos == -1 ) { // New block position will be at the end of the array $iptc_block_pos = count( $Photoshop_IRB_data ); } // Write the new IRB resource to the Photoshop IRB array with no data $Photoshop_IRB_data[$iptc_block_pos] = array( "ResID" => 0x0404, "ResName" => $GLOBALS['Photoshop_ID_Names'][ 0x0404 ], "ResDesc" => $GLOBALS[ "Photoshop_ID_Descriptions" ][ 0x0404 ], "ResEmbeddedName" => "\x00\x00", "ResData" => put_IPTC( $new_IPTC_block ) ); // Return the modified IRB return $Photoshop_IRB_data; } /****************************************************************************** * End of Function: put_Photoshop_IPTC ******************************************************************************/ /****************************************************************************** * * Function: Interpret_IRB_to_HTML * * Description: Generates html showing the information contained in a Photoshop * IRB data array, as retrieved with get_Photoshop_IRB, including * any IPTC-NAA IIM records found. * * Please note that the following resource numbers are not currently * decoded: ( Many of these do not apply to JPEG images) * 0x03E9, 0x03EE, 0x03EF, 0x03F0, 0x03F1, 0x03F2, 0x03F6, 0x03F9, * 0x03FA, 0x03FB, 0x03FD, 0x03FE, 0x0400, 0x0401, 0x0402, 0x0405, * 0x040E, 0x040F, 0x0410, 0x0412, 0x0413, 0x0415, 0x0416, 0x0417, * 0x041B, 0x041C, 0x041D, 0x0BB7 * * ( Also these Obsolete resource numbers) * 0x03E8, 0x03EB, 0x03FC, 0x03FF, 0x0403 * * * Parameters: IRB_array - a Photoshop IRB data array as from get_Photoshop_IRB * filename - the name of the JPEG file being processed ( used * by the script which displays the Photoshop thumbnail) * * * Returns: output_str - the HTML string * ******************************************************************************/ function Interpret_IRB_to_HTML( $IRB_array, $filename ) { // Create a string to receive the HTML $output_str = ""; // Check if the Photoshop IRB array is valid if ( $IRB_array !== FALSE ) { // Create another string to receive secondary HTML to be appended at the end $secondary_output_str = ""; // Add the Heading to the HTML $output_str .= "
$Resource_Name | " . htmlentities( $IRB_Resource['ResData'] ) ." |
$Resource_Name | Image is Copyrighted Material |
$Resource_Name | Image is Not Copyrighted Material |
$Resource_Name | Global lighting angle for effects layer = " . hexdec( bin2hex( $IRB_Resource['ResData'] ) ) . " degrees |
$Resource_Name | Global Altitude = " . hexdec( bin2hex( $IRB_Resource['ResData'] ) ) . " |
$Resource_Name | \n"; $output_str .= "Version = " . hexdec( bin2hex( substr( $IRB_Resource['ResData'], 0, 4 ) ) ) . "\n"; $output_str .= "Has Real Merged Data = " . ord( $IRB_Resource['ResData']{4} ) . "\n"; $writer_size = hexdec( bin2hex( substr( $IRB_Resource['ResData'], 5, 4 ) ) ) * 2; $output_str .= "Writer Name = " . HTML_UTF16_Escape( substr( $IRB_Resource['ResData'], 9, $writer_size ), TRUE ) . "\n"; $reader_size = hexdec( bin2hex( substr( $IRB_Resource['ResData'], 9 + $writer_size , 4 ) ) ) * 2; $output_str .= "Reader Name = " . HTML_UTF16_Escape( substr( $IRB_Resource['ResData'], 13 + $writer_size, $reader_size ), TRUE ) . "\n"; $output_str .= "File Version = " . hexdec( bin2hex( substr( $IRB_Resource['ResData'], 13 + $writer_size + $reader_size, 4 ) ) ) . "\n"; $output_str .= " |
$Resource_Name | Intentionally untagged - any assumed ICC profile handling disabled |
$Resource_Name | Unknown value (0x" .bin2hex( $IRB_Resource['ResData'] ). ") |
$Resource_Name | ";
// Unpack the first 24 bytes
$Slices_Info = unpack("NVersion/NBound_top/NBound_left/NBound_bottom/NBound_right/NStringlen", $IRB_Resource['ResData'] );
$output_str .= "Version = " . $Slices_Info['Version'] . " \n"; $output_str .= "Bounding Rectangle = Top:" . $Slices_Info['Bound_top'] . ", Left:" . $Slices_Info['Bound_left'] . ", Bottom:" . $Slices_Info['Bound_bottom'] . ", Right:" . $Slices_Info['Bound_right'] . " (Pixels) \n"; $Slicepos = 24; // Extract a Unicode String $output_str .= "Text = '" . HTML_UTF16_Escape( substr( $IRB_Resource['ResData'], 24, $Slices_Info['Stringlen']*2), TRUE ) . "' \n"; $Slicepos += $Slices_Info['Stringlen'] * 2; // Unpack the number of Slices $Num_Slices = hexdec( bin2hex( substr( $IRB_Resource['ResData'], $Slicepos, 4 ) ) ); $output_str .= "Number of Slices = " . $Num_Slices . "\n"; $Slicepos += 4; // Cycle through the slices for( $i = 1; $i <= $Num_Slices; $i++ ) { $output_str .= " Slice $i: \n"; // Unpack the first 16 bytes of the slice $SliceA = unpack("NID/NGroupID/NOrigin/NStringlen", substr($IRB_Resource['ResData'], $Slicepos ) ); $Slicepos += 16; $output_str .= "ID = " . $SliceA['ID'] . " \n"; $output_str .= "Group ID = " . $SliceA['GroupID'] . " \n"; $output_str .= "Origin = " . $SliceA['Origin'] . " \n"; // Extract a Unicode String $output_str .= "Text = '" . HTML_UTF16_Escape( substr( $IRB_Resource['ResData'], $Slicepos, $SliceA['Stringlen']*2), TRUE ) . "' \n"; $Slicepos += $SliceA['Stringlen'] * 2; // Unpack the next 24 bytes of the slice $SliceB = unpack("NType/NLeftPos/NTopPos/NRightPos/NBottomPos/NURLlen", substr($IRB_Resource['ResData'], $Slicepos ) ); $Slicepos += 24; $output_str .= "Type = " . $SliceB['Type'] . " \n"; $output_str .= "Position = Top:" . $SliceB['TopPos'] . ", Left:" . $SliceB['LeftPos'] . ", Bottom:" . $SliceB['BottomPos'] . ", Right:" . $SliceB['RightPos'] . " (Pixels) \n"; // Extract a Unicode String $output_str .= "URL = " . HTML_UTF16_Escape( substr( $IRB_Resource['ResData'], $Slicepos, $SliceB['URLlen']*2), TRUE ) . " \n"; $Slicepos += $SliceB['URLlen'] * 2; // Unpack the length of a Unicode String $Targetlen = hexdec( bin2hex( substr( $IRB_Resource['ResData'], $Slicepos, 4 ) ) ); $Slicepos += 4; // Extract a Unicode String $output_str .= "Target = '" . HTML_UTF16_Escape( substr( $IRB_Resource['ResData'], $Slicepos, $Targetlen*2), TRUE ) . "' \n"; $Slicepos += $Targetlen * 2; // Unpack the length of a Unicode String $Messagelen = hexdec( bin2hex( substr( $IRB_Resource['ResData'], $Slicepos, 4 ) ) ); $Slicepos += 4; // Extract a Unicode String $output_str .= "Message = '" . HTML_UTF16_Escape( substr( $IRB_Resource['ResData'], $Slicepos, $Messagelen*2), TRUE ) . "' \n"; $Slicepos += $Messagelen * 2; // Unpack the length of a Unicode String $AltTaglen = hexdec( bin2hex( substr( $IRB_Resource['ResData'], $Slicepos, 4 ) ) ); $Slicepos += 4; // Extract a Unicode String $output_str .= "Alt Tag = '" . HTML_UTF16_Escape( substr( $IRB_Resource['ResData'], $Slicepos, $AltTaglen*2), TRUE ) . "' \n"; $Slicepos += $AltTaglen * 2; // Unpack the HTML flag if ( ord( $IRB_Resource['ResData']{ $Slicepos } ) === 0x01 ) { $output_str .= "Cell Text is HTML \n"; } else { $output_str .= "Cell Text is NOT HTML \n"; } $Slicepos++; // Unpack the length of a Unicode String $CellTextlen = hexdec( bin2hex( substr( $IRB_Resource['ResData'], $Slicepos, 4 ) ) ); $Slicepos += 4; // Extract a Unicode String $output_str .= "Cell Text = '" . HTML_UTF16_Escape( substr( $IRB_Resource['ResData'], $Slicepos, $CellTextlen*2), TRUE ) . "' \n"; $Slicepos += $CellTextlen * 2; // Unpack the last 12 bytes of the slice $SliceC = unpack("NAlignH/NAlignV/CAlpha/CRed/CGreen/CBlue", substr($IRB_Resource['ResData'], $Slicepos ) ); $Slicepos += 12; $output_str .= "Alignment = Horizontal:" . $SliceC['AlignH'] . ", Vertical:" . $SliceC['AlignV'] . " \n"; $output_str .= "Alpha Colour = " . $SliceC['Alpha'] . " \n"; $output_str .= "Red = " . $SliceC['Red'] . " \n"; $output_str .= "Green = " . $SliceC['Green'] . " \n"; $output_str .= "Blue = " . $SliceC['Blue'] . "\n"; } $output_str .= " |
$Resource_Name | ";
// Unpack the Grids info
$Grid_Info = unpack("NVersion/NGridCycleH/NGridCycleV/NGuideCount", $IRB_Resource['ResData'] );
$output_str .= "Version = " . $Grid_Info['Version'] . " \n"; $output_str .= "Grid Cycle = " . $Grid_Info['GridCycleH']/32 . " Pixel(s) x " . $Grid_Info['GridCycleV']/32 . " Pixel(s) \n"; $output_str .= "Number of Guides = " . $Grid_Info['GuideCount'] . "\n"; // Cycle through the Guides for( $i = 0; $i < $Grid_Info['GuideCount']; $i++ ) { // Unpack the info for this guide $Guide_Info = unpack("NLocation/CDirection", substr($IRB_Resource['ResData'],16+$i*5,5) ); $output_str .= " Guide $i : Location = " . $Guide_Info['Location']/32 . " Pixel(s) from edge"; if ( $Guide_Info['Direction'] === 0 ) { $output_str .= ", Vertical\n"; } else { $output_str .= ", Horizontal\n"; } } break; $output_str .= " |
$Resource_Name | ";
switch ( $Qual_Info['Quality'] )
{
case 0xFFFD:
$output_str .= "Quality 1 (Low) \n"; break; case 0xFFFE: $output_str .= "Quality 2 (Low) \n"; break; case 0xFFFF: $output_str .= "Quality 3 (Low) \n"; break; case 0x0000: $output_str .= "Quality 4 (Low) \n"; break; case 0x0001: $output_str .= "Quality 5 (Medium) \n"; break; case 0x0002: $output_str .= "Quality 6 (Medium) \n"; break; case 0x0003: $output_str .= "Quality 7 (Medium) \n"; break; case 0x0004: $output_str .= "Quality 8 (High) \n"; break; case 0x0005: $output_str .= "Quality 9 (High) \n"; break; case 0x0006: $output_str .= "Quality 10 (Maximum) \n"; break; case 0x0007: $output_str .= "Quality 11 (Maximum) \n"; break; case 0x0008: $output_str .= "Quality 12 (Maximum) \n"; break; default: $output_str .= "Unknown Quality (" . $Qual_Info['Quality'] . ") \n"; break; } switch ( $Qual_Info['Format'] ) { case 0x0000: $output_str .= "Standard Format\n"; break; case 0x0001: $output_str .= "Optimised Format\n"; break; case 0x0101: $output_str .= "Progressive Format \n"; break; default: $output_str .= "Unknown Format (" . $Qual_Info['Format'] .")\n"; break; } if ( $Qual_Info['Format'] == 0x0101 ) { switch ( $Qual_Info['Scans'] ) { case 0x0001: $output_str .= "3 Scans\n"; break; case 0x0002: $output_str .= "4 Scans\n"; break; case 0x0003: $output_str .= "5 Scans\n"; break; default: $output_str .= "Unknown number of scans (" . $Qual_Info['Scans'] .")\n"; break; } } $output_str .= " |
$Resource_Name | \n"; $output_str .= "Format = " . (( $thumb_data['Format'] == 1 ) ? "JPEG RGB\n" : "Raw RGB\n"); $output_str .= "Width = " . $thumb_data['Width'] . "\n"; $output_str .= "Height = " . $thumb_data['Height'] . "\n"; $output_str .= "Padded Row Bytes = " . $thumb_data['WidthBytes'] . " bytes\n"; $output_str .= "Total Size = " . $thumb_data['Size'] . " bytes\n"; $output_str .= "Compressed Size = " . $thumb_data['CompressedSize'] . " bytes\n"; $output_str .= "Bits per Pixel = " . $thumb_data['BitsPixel'] . " bits\n"; $output_str .= "Number of planes = " . $thumb_data['Planes'] . " bytes\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_ps_thumb.php" , getcwd ( ) ); $link_str .= "?filename="; $link_str .= get_relative_path( $filename, dirname(__FILE__) ); // Add thumbnail link to html $output_str .= "Thumbnail Data:\n"; $output_str .= " |
$Resource_Name | " . hexdec( bin2hex( $IRB_Resource['ResData'] ) ) . " |
$Resource_Name | \n";
$output_str .= "$URL_count URL's in list \n"; $urlstr = substr( $IRB_Resource['ResData'], 4 ); // TODO: Check if URL List in Photoshop IRB works for( $i = 0; $i < $URL_count; $i++ ) { $url_data = unpack( "NLong/NID/NURLSize", $urlstr ); $output_str .= "URL $i info: long = " . $url_data['Long'] .", "; $output_str .= "ID = " . $url_data['ID'] . ", "; $urlstr = substr( $urlstr, 12 ); $url = substr( $urlstr, 0, $url_data['URLSize'] ); $output_str .= "URL = " . HTML_UTF16_Escape( $url, TRUE ) . " \n"; } $output_str .= " |
$Resource_Name | \n"; $output_str .= Interpret_Halftone( $IRB_Resource['ResData'] ); $output_str .= " |
$Resource_Name | \n"; $output_str .= "Cyan Halftoning Info:\n" . Interpret_Halftone( substr( $IRB_Resource['ResData'], 0, 18 ) ) . "\n\n"; $output_str .= "Magenta Halftoning Info:\n" . Interpret_Halftone( substr( $IRB_Resource['ResData'], 18, 18 ) ) . "\n\n"; $output_str .= "Yellow Halftoning Info:\n" . Interpret_Halftone( substr( $IRB_Resource['ResData'], 36, 18 ) ) . "\n"; $output_str .= "Black Halftoning Info:\n" . Interpret_Halftone( substr( $IRB_Resource['ResData'], 54, 18 ) ) . "\n"; $output_str .= " |
$Resource_Name | \n"; $output_str .= Interpret_Transfer_Function( substr( $IRB_Resource['ResData'], 0, 28 ) ) ; $output_str .= " |
$Resource_Name | \n"; $output_str .= "Red Transfer Function: \n" . Interpret_Transfer_Function( substr( $IRB_Resource['ResData'], 0, 28 ) ) . "\n\n"; $output_str .= "Green Transfer Function: \n" . Interpret_Transfer_Function( substr( $IRB_Resource['ResData'], 28, 28 ) ) . "\n\n"; $output_str .= "Blue Transfer Function: \n" . Interpret_Transfer_Function( substr( $IRB_Resource['ResData'], 56, 28 ) ) . "\n"; $output_str .= " |
$Resource_Name | \n"; if ( $IRB_Resource['ResData']{0} == "\x01" ) { $output_str .= "Labels Selected\n"; } else { $output_str .= "Labels Not Selected\n"; } if ( $IRB_Resource['ResData']{1} == "\x01" ) { $output_str .= "Crop Marks Selected\n"; } else { $output_str .= "Crop Marks Not Selected\n"; } if ( $IRB_Resource['ResData']{2} == "\x01" ) { $output_str .= "Color Bars Selected\n"; } else { $output_str .= "Color Bars Not Selected\n"; } if ( $IRB_Resource['ResData']{3} == "\x01" ) { $output_str .= "Registration Marks Selected\n"; } else { $output_str .= "Registration Marks Not Selected\n"; } if ( $IRB_Resource['ResData']{4} == "\x01" ) { $output_str .= "Negative Selected\n"; } else { $output_str .= "Negative Not Selected\n"; } if ( $IRB_Resource['ResData']{5} == "\x01" ) { $output_str .= "Flip Selected\n"; } else { $output_str .= "Flip Not Selected\n"; } if ( $IRB_Resource['ResData']{6} == "\x01" ) { $output_str .= "Interpolate Selected\n"; } else { $output_str .= "Interpolate Not Selected\n"; } if ( $IRB_Resource['ResData']{7} == "\x01" ) { $output_str .= "Caption Selected"; } else { $output_str .= "Caption Not Selected"; } $output_str .= " |
$Resource_Name | \n"; $output_str .= "Version = " . $PrintFlags['Version'] . "\n"; $output_str .= "Centre Crop Marks = " . $PrintFlags['CentCrop'] . "\n"; $output_str .= "Bleed Width = " . $PrintFlags['BleedWidth'] . "\n"; $output_str .= "Bleed Width Scale = " . $PrintFlags['BleedWidthScale']; $output_str .= " |
$Resource_Name | \n"; $output_str .= "Horizontal Resolution = " . ($ResInfo['hRes_int'] + $ResInfo['hResdec']/65536) . " pixels per Inch\n"; $output_str .= "Vertical Resolution = " . ($ResInfo['vRes_int'] + $ResInfo['vResdec']/65536) . " pixels per Inch\n"; if ( $ResInfo['hResUnit'] == 1 ) { $output_str .= "Display units for Horizontal Resolution = Pixels per Inch\n"; } elseif ( $ResInfo['hResUnit'] == 2 ) { $output_str .= "Display units for Horizontal Resolution = Pixels per Centimetre\n"; } else { $output_str .= "Display units for Horizontal Resolution = Unknown Value (". $ResInfo['hResUnit'] .")\n"; } if ( $ResInfo['vResUnit'] == 1 ) { $output_str .= "Display units for Vertical Resolution = Pixels per Inch\n"; } elseif ( $ResInfo['vResUnit'] == 2 ) { $output_str .= "Display units for Vertical Resolution = Pixels per Centimetre\n"; } else { $output_str .= "Display units for Vertical Resolution = Unknown Value (". $ResInfo['vResUnit'] .")\n"; } if ( $ResInfo['widthUnit'] == 1 ) { $output_str .= "Display units for Image Width = Inches\n"; } elseif ( $ResInfo['widthUnit'] == 2 ) { $output_str .= "Display units for Image Width = Centimetres\n"; } elseif ( $ResInfo['widthUnit'] == 3 ) { $output_str .= "Display units for Image Width = Points\n"; } elseif ( $ResInfo['widthUnit'] == 4 ) { $output_str .= "Display units for Image Width = Picas\n"; } elseif ( $ResInfo['widthUnit'] == 5 ) { $output_str .= "Display units for Image Width = Columns\n"; } else { $output_str .= "Display units for Image Width = Unknown Value (". $ResInfo['widthUnit'] .")\n"; } if ( $ResInfo['heightUnit'] == 1 ) { $output_str .= "Display units for Image Height = Inches"; } elseif ( $ResInfo['heightUnit'] == 2 ) { $output_str .= "Display units for Image Height = Centimetres"; } elseif ( $ResInfo['heightUnit'] == 3 ) { $output_str .= "Display units for Image Height = Points"; } elseif ( $ResInfo['heightUnit'] == 4 ) { $output_str .= "Display units for Image Height = Picas"; } elseif ( $ResInfo['heightUnit'] == 5 ) { $output_str .= "Display units for Image Height = Columns"; } else { $output_str .= "Display units for Image Height = Unknown Value (". $ResInfo['heightUnit'] .")"; } $output_str .= " |
$Resource_Name | RESOURCE DECODING NOT IMPLEMENTED YET " . strlen( $IRB_Resource['ResData'] ) . " bytes |
Could not open file $filename
\n"; return FALSE; } fseek( $filehnd, $jpeg_header_data[$EXIF_Location]['SegDataStart'] + 6 ); // Decode the Exif segment into an array and return it $exif_data = process_TIFF_Header( $filehnd, "TIFF" ); // Close File fclose($filehnd); return $exif_data; } /****************************************************************************** * End of Function: get_EXIF_JPEG ******************************************************************************/ /****************************************************************************** * * Function: put_EXIF_JPEG * * Description: Stores information into a Exchangeable Image File Format (EXIF) * APP1 segment from an EXIF array. * * WARNING: Because the EXIF standard allows pointers to data * outside the APP1 segment, if there are any such pointers in * a makernote, this function will DAMAGE them since it will not * be aware that there is an external pointer. This will often * happen with Makernotes that include an embedded thumbnail. * This damage could be prevented where makernotes can be decoded, * but currently this is not implemented. * * * Parameters: exif_data - The array of EXIF data to insert into the JPEG header * jpeg_header_data - The JPEG header into which the EXIF data * should be stored, as from get_jpeg_header_data * * Returns: jpeg_header_data - JPEG header array with the EXIF segment inserted * FALSE - If an error occured * ******************************************************************************/ function put_EXIF_JPEG( $exif_data, $jpeg_header_data ) { // pack the EXIF data into its proper format for a JPEG file $packed_data = get_TIFF_Packed_Data( $exif_data ); if ( $packed_data === FALSE ) { return $jpeg_header_data; } $packed_data = "Exif\x00\x00$packed_data"; //Cycle through the header segments for( $i = 0; $i < count( $jpeg_header_data ); $i++ ) { // If we find an APP1 header, if ( strcmp ( $jpeg_header_data[$i]['SegName'], "APP1" ) == 0 ) { // And if it has the EXIF label, if ( ( strncmp ( $jpeg_header_data[$i]['SegData'], "Exif\x00\x00", 6) == 0 ) || ( strncmp ( $jpeg_header_data[$i]['SegData'], "Exif\x00\xFF", 6) == 0 ) ) // For some reason, some files have a faulty EXIF name which has a 0xFF in it { // Found a preexisting EXIF block - Replace it with the new one and return. $jpeg_header_data[$i]['SegData'] = $packed_data; return $jpeg_header_data; } } } // No preexisting segment segment found, insert a new one at the start of the header data. // Determine highest position of an APP segment at or below APP3, so we can put the // new APP3 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 APP3, if ( ( $jpeg_header_data[$i]['SegType'] >= 0xE0 ) && ( $jpeg_header_data[$i]['SegType'] <= 0xE3 ) ) { // Found an APP segment at or below APP12 $highest_APP = $i; } } // No preexisting EXIF block found, insert a new one at the start of the header data. array_splice($jpeg_header_data, $highest_APP + 1 , 0, array( array( "SegType" => 0xE1, "SegName" => "APP1", "SegDesc" => $GLOBALS[ "JPEG_Segment_Descriptions" ][ 0xE1 ], "SegData" => $packed_data ) ) ); return $jpeg_header_data; } /****************************************************************************** * End of Function: put_EXIF_JPEG ******************************************************************************/ /****************************************************************************** * * Function: get_Meta_JPEG * * Description: Retrieves information from a Meta APP3 segment and returns it * in an array. Uses information supplied by the * get_jpeg_header_data function. * The Meta segment has the same format as an EXIF segment, but * uses different tags * * Parameters: filename - the filename of the JPEG image to process * * Returns: OutputArray - Array of Meta records * FALSE - If an error occured in decoding * ******************************************************************************/ function get_Meta_JPEG( $filename ) { // Change: Added as of version 1.11 // Check if a wrapper is being used - these are not currently supported (see notes at top of file) if ( ( stristr ( $filename, "http://" ) != FALSE ) || ( stristr ( $filename, "ftp://" ) != FALSE ) ) { // A HTTP or FTP wrapper is being used - show a warning and abort echo "HTTP and FTP wrappers are currently not supported with Meta - See EXIF/Meta functionality documentation - a local file must be specifiedCould not open file $filename
\n"; return FALSE; } fseek( $filehnd, $jpeg_header_data[$Meta_Location]['SegDataStart'] + 6 ); // Decode the Meta segment into an array and return it $meta = process_TIFF_Header( $filehnd, "Meta" ); // Close File fclose($filehnd); return $meta; } /****************************************************************************** * End of Function: get_Meta ******************************************************************************/ /****************************************************************************** * * Function: put_Meta_JPEG * * Description: Stores information into a Meta APP3 segment from a Meta array. * * * WARNING: Because the Meta (EXIF) standard allows pointers to data * outside the APP1 segment, if there are any such pointers in * a makernote, this function will DAMAGE them since it will not * be aware that there is an external pointer. This will often * happen with Makernotes that include an embedded thumbnail. * This damage could be prevented where makernotes can be decoded, * but currently this is not implemented. * * * Parameters: meta_data - The array of Meta data to insert into the JPEG header * jpeg_header_data - The JPEG header into which the Meta data * should be stored, as from get_jpeg_header_data * * Returns: jpeg_header_data - JPEG header array with the Meta segment inserted * FALSE - If an error occured * ******************************************************************************/ function put_Meta_JPEG( $meta_data, $jpeg_header_data ) { // pack the Meta data into its proper format for a JPEG file $packed_data = get_TIFF_Packed_Data( $meta_data ); if ( $packed_data === FALSE ) { return $jpeg_header_data; } $packed_data = "Meta\x00\x00$packed_data"; //Cycle through the header segments for( $i = 0; $i < count( $jpeg_header_data ); $i++ ) { // If we find an APP1 header, if ( strcmp ( $jpeg_header_data[$i]['SegName'], "APP3" ) == 0 ) { // And if it has the Meta label, if ( ( strncmp ( $jpeg_header_data[$i]['SegData'], "Meta\x00\x00", 6) == 0 ) || ( strncmp ( $jpeg_header_data[$i]['SegData'], "META\x00\x00", 6) == 0 ) ) { // Found a preexisting Meta block - Replace it with the new one and return. $jpeg_header_data[$i]['SegData'] = $packed_data; return $jpeg_header_data; } } } // No preexisting segment segment found, insert a new one at the start of the header data. // Determine highest position of an APP segment at or below APP3, so we can put the // new APP3 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 APP3, if ( ( $jpeg_header_data[$i]['SegType'] >= 0xE0 ) && ( $jpeg_header_data[$i]['SegType'] <= 0xE3 ) ) { // Found an APP segment at or below APP12 $highest_APP = $i; } } // No preexisting Meta block found, insert a new one at the start of the header data. array_splice($jpeg_header_data, $highest_APP + 1 , 0, array( array( "SegType" => 0xE3, "SegName" => "APP3", "SegDesc" => $GLOBALS[ "JPEG_Segment_Descriptions" ][ 0xE1 ], "SegData" => $packed_data ) ) ); return $jpeg_header_data; } /****************************************************************************** * End of Function: put_Meta_JPEG ******************************************************************************/ /****************************************************************************** * * Function: get_EXIF_TIFF * * Description: Retrieves information from a Exchangeable Image File Format (EXIF) * within a TIFF file and returns it in an array. * * Parameters: filename - the filename of the TIFF image to process * * Returns: OutputArray - Array of EXIF records * FALSE - If an error occured in decoding * ******************************************************************************/ function get_EXIF_TIFF( $filename ) { // Change: Added as of version 1.11 // Check if a wrapper is being used - these are not currently supported (see notes at top of file) if ( ( stristr ( $filename, "http://" ) != FALSE ) || ( stristr ( $filename, "ftp://" ) != FALSE ) ) { // A HTTP or FTP wrapper is being used - show a warning and abort echo "HTTP and FTP wrappers are currently not supported with TIFF - See EXIF/TIFF functionality documentation - a local file must be specifiedCould not open file $filename
\n"; return FALSE; } // Decode the Exif segment into an array and return it $exif_data = process_TIFF_Header( $filehnd, "TIFF" ); // Close File fclose($filehnd); return $exif_data; } /****************************************************************************** * End of Function: get_EXIF_TIFF ******************************************************************************/ /****************************************************************************** * * Function: Interpret_EXIF_to_HTML * * Description: Generates html detailing the contents an APP1 EXIF array * which was retrieved with a get_EXIF_.... function. * Can also be used for APP3 Meta arrays. * * Parameters: Exif_array - the EXIF array,as read from get_EXIF_.... * filename - the name of the Image file being processed ( used * by scripts which displays EXIF thumbnails) * * Returns: output_str - A string containing the HTML * ******************************************************************************/ function Interpret_EXIF_to_HTML( $Exif_array, $filename ) { // Create the string to receive the html output $output_str = ""; // Check if the array to process is valid if ( $Exif_array === FALSE ) { // Exif Array is not valid - abort processing return $output_str; } // Ouput the heading according to what type of tags were used in processing if ( $Exif_array[ 'Tags Name' ] == "TIFF" ) { $output_str .= "Error: Corrupted EXIF
\n"; return FALSE; } $Output_Array[] = $IFD_Array; } while ( $Next_Offset != 0 ); // Until the Next IFD Offset is zero // return resulting array return $Output_Array ; } /****************************************************************************** * End of Function: read_Multiple_IFDs ******************************************************************************/ /****************************************************************************** * * Internal Function: read_IFD_universal * * Description: Reads and interprets a standard or Non-standard Image File * Directory (IFD), and returns the entries in an array * * Parameters: filehnd - a handle for the image file being read, positioned at the start * of the IFD * Tiff_offset - The offset of the TIFF header from the start of the file * Byte_Align - either "MM" or "II" indicating Motorola or Intel Byte alignment * Tag_Definitions_Name - The name of the Tag Definitions group within the global array IFD_Tag_Definitions * local_offsets - True indicates that offset data should be interpreted as being relative to the start of the currrent entry * False (normal) indicates offests are relative to start of Tiff header as per IFD standard * read_next_ptr - True (normal) indicates that a pointer to the next IFD should be read at the end of the IFD * False indicates that no pointer follows the IFD * * Returns: OutputArray - Array of IFD entries * Next_Offset - Offset to next IFD (zero = no next IFD) * ******************************************************************************/ function read_IFD_universal( $filehnd, $Tiff_offset, $Byte_Align, $Tag_Definitions_Name, $local_offsets = FALSE, $read_next_ptr = TRUE ) { if ( ( $filehnd == NULL ) || ( feof( $filehnd ) ) ) { return array (FALSE , 0); } // Record the Name of the Tag Group used for this IFD in the output array $OutputArray[ 'Tags Name' ] = $Tag_Definitions_Name; // Record the offset of the TIFF header in the output array $OutputArray[ 'Tiff Offset' ] = $Tiff_offset; // First 2 bytes of IFD are number of entries in the IFD $No_Entries_str = network_safe_fread( $filehnd, 2 ); $No_Entries = get_IFD_Data_Type( $No_Entries_str, 3, $Byte_Align ); // If the data is corrupt, the number of entries may be huge, which will cause errors // This is often caused by a lack of a Next-IFD pointer if ( $No_Entries> 10000 ) { // Huge number of entries - abort echo "Error: huge number of EXIF entries - EXIF is probably Corrupted
\n"; return array ( FALSE , 0); } // If the data is corrupt or just stupid, the number of entries may zero, // Indicate this by returning false if ( $No_Entries === 0 ) { // No entries - abort return array ( FALSE , 0); } // Save the file position where first IFD record starts as non-standard offsets // need to know this to calculate an absolute offset $IFD_first_rec_pos = ftell( $filehnd ); // Read in the IFD structure $IFD_Data = network_safe_fread( $filehnd, 12 * $No_Entries ); // Check if the entire IFD was able to be read if ( strlen( $IFD_Data ) != (12 * $No_Entries) ) { // Couldn't read the IFD Data properly, Some Casio files have no Next IFD pointer, hence cause this error echo "Error: EXIF Corrupted
\n"; return array(FALSE, 0); } // Last 4 bytes of a standard IFD are the offset to the next IFD // Some NON-Standard IFD implementations do not have this, hence causing problems if it is read // If the Next IFD pointer has been requested to be read, if ( $read_next_ptr ) { // Read the pointer to the next IFD $Next_Offset_str = network_safe_fread( $filehnd, 4 ); $Next_Offset = get_IFD_Data_Type( $Next_Offset_str, 4, $Byte_Align ); } else { // Otherwise set the pointer to zero ( no next IFD ) $Next_Offset = 0; } // Initialise current position to the start $pos = 0; // Loop for reading IFD entries for ( $i = 0; $i < $No_Entries; $i++ ) { // First 2 bytes of IFD entry are the tag number ( Unsigned Short ) $Tag_No_str = substr( $IFD_Data, $pos, 2 ); $Tag_No = get_IFD_Data_Type( $Tag_No_str, 3, $Byte_Align ); $pos += 2; // Next 2 bytes of IFD entry are the data format ( Unsigned Short ) $Data_Type_str = substr( $IFD_Data, $pos, 2 ); $Data_Type = get_IFD_Data_Type( $Data_Type_str, 3, $Byte_Align ); $pos += 2; // If Datatype is not between 1 and 12, then skip this entry, it is probably corrupted or custom if (( $Data_Type > 12 ) || ( $Data_Type < 1 ) ) { $pos += 8; continue 1; // Stop trying to process the tag any further and skip to the next one } // Next 4 bytes of IFD entry are the data count ( Unsigned Long ) $Data_Count_str = substr( $IFD_Data, $pos, 4 ); $Data_Count = get_IFD_Data_Type( $Data_Count_str, 4, $Byte_Align ); $pos += 4; if ( $Data_Count > 100000 ) { echo "Error: huge EXIF data count - EXIF is probably Corrupted
\n"; // Some Casio files have no Next IFD pointer, hence cause errors return array ( FALSE , 0); } // Total Data size is the Data Count multiplied by the size of the Data Type $Total_Data_Size = $GLOBALS['IFD_Data_Sizes'][ $Data_Type ] * $Data_Count; $Data_Start_pos = -1; // If the total data size is larger than 4 bytes, then the data part is the offset to the real data if ( $Total_Data_Size > 4 ) { // Not enough room for data - offset provided instead $Data_Offset_str = substr( $IFD_Data, $pos, 4 ); $Data_Start_pos = get_IFD_Data_Type( $Data_Offset_str, 4, $Byte_Align ); // In some NON-STANDARD makernotes, the offset is relative to the start of the current IFD entry if ( $local_offsets ) { // This is a NON-Standard IFD, seek relative to the start of the current tag fseek( $filehnd, $IFD_first_rec_pos + $pos - 8 + $Data_Start_pos ); } else { // This is a normal IFD, seek relative to the start of the TIFF header fseek( $filehnd, $Tiff_offset + $Data_Start_pos ); } // Read the data block from the offset position $DataStr = network_safe_fread( $filehnd, $Total_Data_Size ); } else { // The data block is less than 4 bytes, and is provided in the IFD entry, so read it $DataStr = substr( $IFD_Data, $pos, $Total_Data_Size ); } // Increment the position past the data $pos += 4; // Now create the entry for output array $Data_Array = array( ); // Read the data items from the data block if ( ( $Data_Type != 2 ) && ( $Data_Type != 7 ) ) { // The data type is Numerical, Read the data items from the data block for ( $j = 0; $j < $Data_Count; $j++ ) { $Part_Data_Str = substr( $DataStr, $j * $GLOBALS['IFD_Data_Sizes'][ $Data_Type ], $GLOBALS['IFD_Data_Sizes'][ $Data_Type ] ); $Data_Array[] = get_IFD_Data_Type( $Part_Data_Str, $Data_Type, $Byte_Align ); } } elseif ( $Data_Type == 2 ) { // The data type is String(s) (type 2) // Strip the last terminating Null $DataStr = substr( $DataStr, 0, strlen($DataStr)-1 ); // Split the data block into multiple strings whereever there is a Null $Data_Array = explode( "\x00", $DataStr ); } else { // The data type is Unknown (type 7) // Do nothing to data $Data_Array = $DataStr; } // If this is a Sub-IFD entry, if ( ( array_key_exists( $Tag_No, $GLOBALS[ "IFD_Tag_Definitions" ][$Tag_Definitions_Name] ) ) && ( "SubIFD" == $GLOBALS[ "IFD_Tag_Definitions" ][$Tag_Definitions_Name][ $Tag_No ]['Type'] ) ) { // This is a Sub-IFD entry, go and process the data forming Sub-IFD and use its output array as the new data for this entry fseek( $filehnd, $Tiff_offset + $Data_Array[0] ); $Data_Array = read_Multiple_IFDs( $filehnd, $Tiff_offset, $Byte_Align, $GLOBALS[ "IFD_Tag_Definitions" ][$Tag_Definitions_Name][ $Tag_No ]['Tags Name'] ); } $desc = ""; $units = ""; // Check if this tag exists in the list of tag definitions, if ( array_key_exists ( $Tag_No, $GLOBALS[ "IFD_Tag_Definitions" ][$Tag_Definitions_Name]) ) { if ( array_key_exists ( 'Description', $GLOBALS[ "IFD_Tag_Definitions" ][$Tag_Definitions_Name][ $Tag_No ] ) ) { $desc = $GLOBALS[ "IFD_Tag_Definitions" ][$Tag_Definitions_Name][ $Tag_No ]['Description']; } if ( array_key_exists ( 'Units', $GLOBALS[ "IFD_Tag_Definitions" ][$Tag_Definitions_Name][ $Tag_No ] ) ) { $units = $GLOBALS[ "IFD_Tag_Definitions" ][$Tag_Definitions_Name][ $Tag_No ]['Units']; } // Tag exists in definitions, append details to output array $OutputArray[ $Tag_No ] = array ( "Tag Number" => $Tag_No, "Tag Name" => $GLOBALS[ "IFD_Tag_Definitions" ][$Tag_Definitions_Name][ $Tag_No ]['Name'], "Tag Description" => $desc, "Data Type" => $Data_Type, "Type" => $GLOBALS[ "IFD_Tag_Definitions" ][$Tag_Definitions_Name][ $Tag_No ]['Type'], "Units" => $units, "Data" => $Data_Array ); } else { // Tag doesnt exist in definitions, append unknown details to output array $OutputArray[ $Tag_No ] = array ( "Tag Number" => $Tag_No, "Tag Name" => "Unknown Tag #" . $Tag_No, "Tag Description" => "", "Data Type" => $Data_Type, "Type" => "Unknown", "Units" => "", "Data" => $Data_Array ); } // Some information of type "Unknown" (type 7) might require information about // how it's position and byte alignment in order to be decoded if ( $Data_Type == 7 ) { $OutputArray[ $Tag_No ]['Offset'] = $Data_Start_pos; $OutputArray[ $Tag_No ]['Byte Align'] = $Byte_Align; } //////////////////////////////////////////////////////////////////////// // Special Data handling //////////////////////////////////////////////////////////////////////// // Check if this is a Print Image Matching entry if ( $OutputArray[ $Tag_No ]['Type'] == "PIM" ) { // This is a Print Image Matching entry, decode it. $OutputArray[ $Tag_No ] = Decode_PIM( $OutputArray[ $Tag_No ], $Tag_Definitions_Name ); } // Interpret the entry into a text string using a custom interpreter $text_val = get_Tag_Text_Value( $OutputArray[ $Tag_No ], $Tag_Definitions_Name ); // Check if a text string was generated if ( $text_val !== FALSE ) { // A string was generated, append it to the output array entry $OutputArray[ $Tag_No ]['Text Value'] = $text_val; $OutputArray[ $Tag_No ]['Decoded'] = TRUE; } else { // A string was NOT generated, append a generic string to the output array entry $OutputArray[ $Tag_No ]['Text Value'] = get_IFD_value_as_text( $OutputArray[ $Tag_No ] ) . " " . $units; $OutputArray[ $Tag_No ]['Decoded'] = FALSE; } // Check if this entry is the Maker Note if ( ( $Tag_Definitions_Name == "EXIF" ) && ( $Tag_No == 37500 ) ) { // Save some extra information which will allow Makernote Decoding with the output array entry $OutputArray[ $Tag_No ]['Offset'] = $Data_Start_pos; $OutputArray[ $Tag_No ][ 'Tiff Offset' ] = $Tiff_offset; $OutputArray[ $Tag_No ]['ByteAlign'] = $Byte_Align; // Save a pointer to this entry for Maker note processing later $GLOBALS[ "Maker_Note_Tag" ] = & $OutputArray[ $Tag_No ]; } // Check if this is a IPTC/NAA Record within the EXIF IFD if ( ( ( $Tag_Definitions_Name == "EXIF" ) || ( $Tag_Definitions_Name == "TIFF" ) ) && ( $Tag_No == 33723 ) ) { // This is a IPTC/NAA Record, interpret it and put result in the data for this entry $OutputArray[ $Tag_No ]['Data'] = get_IPTC( $DataStr ); $OutputArray[ $Tag_No ]['Decoded'] = TRUE; } // Change: Check for embedded XMP as of version 1.11 // Check if this is a XMP Record within the EXIF IFD if ( ( ( $Tag_Definitions_Name == "EXIF" ) || ( $Tag_Definitions_Name == "TIFF" ) ) && ( $Tag_No == 700 ) ) { // This is a XMP Record, interpret it and put result in the data for this entry $OutputArray[ $Tag_No ]['Data'] = read_XMP_array_from_text( $DataStr ); $OutputArray[ $Tag_No ]['Decoded'] = TRUE; } // Change: Check for embedded IRB as of version 1.11 // Check if this is a Photoshop IRB Record within the EXIF IFD if ( ( ( $Tag_Definitions_Name == "EXIF" ) || ( $Tag_Definitions_Name == "TIFF" ) ) && ( $Tag_No == 34377 ) ) { // This is a Photoshop IRB Record, interpret it and put result in the data for this entry $OutputArray[ $Tag_No ]['Data'] = unpack_Photoshop_IRB_Data( $DataStr ); $OutputArray[ $Tag_No ]['Decoded'] = TRUE; } // Exif Thumbnail // Check that both the thumbnail length and offset entries have been processed, // and that this is one of them if ( ( ( ( $Tag_No == 513 ) && ( array_key_exists( 514, $OutputArray ) ) ) || ( ( $Tag_No == 514 ) && ( array_key_exists( 513, $OutputArray ) ) ) ) && ( $Tag_Definitions_Name == "TIFF" ) ) { // Seek to the start of the thumbnail using the offset entry fseek( $filehnd, $Tiff_offset + $OutputArray[513]['Data'][0] ); // Read the thumbnail data, and replace the offset data with the thumbnail $OutputArray[513]['Data'] = network_safe_fread( $filehnd, $OutputArray[514]['Data'][0] ); } // Casio Thumbnail // Check that both the thumbnail length and offset entries have been processed, // and that this is one of them if ( ( ( ( $Tag_No == 0x0004 ) && ( array_key_exists( 0x0003, $OutputArray ) ) ) || ( ( $Tag_No == 0x0003 ) && ( array_key_exists( 0x0004, $OutputArray ) ) ) ) && ( $Tag_Definitions_Name == "Casio Type 2" ) ) { // Seek to the start of the thumbnail using the offset entry fseek( $filehnd, $Tiff_offset + $OutputArray[0x0004]['Data'][0] ); // Read the thumbnail data, and replace the offset data with the thumbnail $OutputArray[0x0004]['Data'] = network_safe_fread( $filehnd, $OutputArray[0x0003]['Data'][0] ); } // Minolta Thumbnail // Check that both the thumbnail length and offset entries have been processed, // and that this is one of them if ( ( ( ( $Tag_No == 0x0088 ) && ( array_key_exists( 0x0089, $OutputArray ) ) ) || ( ( $Tag_No == 0x0089 ) && ( array_key_exists( 0x0088, $OutputArray ) ) ) ) && ( $Tag_Definitions_Name == "Olympus" ) ) { // Seek to the start of the thumbnail using the offset entry fseek( $filehnd, $Tiff_offset + $OutputArray[0x0088]['Data'][0] ); // Read the thumbnail data, and replace the offset data with the thumbnail $OutputArray[0x0088]['Data'] = network_safe_fread( $filehnd, $OutputArray[0x0089]['Data'][0] ); // Sometimes the minolta thumbnail data is empty (or the offset is corrupt, which results in the same thing) // Check if the thumbnail data exists if ( $OutputArray[0x0088]['Data'] != "" ) { // Thumbnail exists // Minolta Thumbnails are missing their first 0xFF for some reason, // which is replaced with some weird character, so fix this $OutputArray[0x0088]['Data']{0} = "\xFF"; } else { // Thumbnail doesnt exist - make it obvious $OutputArray[0x0088]['Data'] = FALSE; } } } // Return the array of IFD entries and the offset to the next IFD return array ($OutputArray , $Next_Offset); } /****************************************************************************** * End of Function: read_IFD_universal ******************************************************************************/ /****************************************************************************** * * Internal Function: get_Tag_Text_Value * * Description: Attempts to interpret an IFD entry into a text string using the * information in the IFD_Tag_Definitions global array. * * Parameters: Tag - The IFD entry to process * Tag_Definitions_Name - The name of the tag definitions to use from within the IFD_Tag_Definitions global array * * Returns: String - if the tag was successfully decoded into a text string * FALSE - if the tag could not be decoded using the information * in the IFD_Tag_Definitions global array * ******************************************************************************/ function get_Tag_Text_Value( $Tag, $Tag_Definitions_Name ) { // Check what format the entry is specified as if ( $Tag['Type'] == "String" ) { // Format is Text String // If "Unknown" (type 7) data type, if ( $Tag['Data Type'] == 7 ) { // Return data as is. return $Tag['Data']; } else { // Otherwise return the default string value of the datatype return get_IFD_value_as_text( $Tag ); } } else if ( $Tag['Type'] == "Character Coded String" ) { // Format is Character Coded String (First 8 characters indicate coding scheme) // Convert Data to a string if ( $Tag['Data Type'] == 7 ) { // If it is type "Unknown" (type 7) use data as is $data = $Tag['Data']; } else { // Otherwise use the default string value of the datatype $data = get_IFD_value_as_text( $Tag ); } // Some implementations allow completely data with no Coding Scheme Name, // so we need to handle this to avoid errors if ( trim( $data ) == "" ) { return ""; } // Extract the Coding Scheme Name from the first 8 characters $char_code = substr( $data, 0, 8 ); // Extract the Data part from after the first 8 characters $characters = substr( $data, 8 ); // Check coding scheme and interpret as neccessary if ( $char_code === "ASCII\x00\x00\x00" ) { // ASCII coding - return data as is. return $characters; } elseif ( ( $char_code === "UNICODE\x00" ) || ( $char_code === "Unicode\x00" ) ) // Note lowercase is non standard { // Unicode coding - interpret and return result. return xml_UTF16_clean( $characters, TRUE ); } else { // Unknown coding - return string indicating this return "Unsupported character coding : \"$char_code\"\n\"" . trim($characters) . "\""; } break; } else if ( $Tag['Type'] == "Numeric" ) { // Format is numeric - return default text value with any required units text appended if ( array_key_exists ( 'Units', $GLOBALS[ "IFD_Tag_Definitions" ][$Tag_Definitions_Name][ $Tag["Tag Number"] ] ) ) { $units = $GLOBALS[ "IFD_Tag_Definitions" ][$Tag_Definitions_Name][ $Tag["Tag Number"] ]['Units']; } else { $units = ""; } return get_IFD_value_as_text( $Tag ) . " " . $units; } else if ( $Tag['Type'] == "Lookup" ) { // Format is a Lookup Table // Get a numeric value to use in lookup if ( is_array( $Tag['Data'] ) ) { // If data is an array, use first element $first_val = $Tag['Data'][0]; } else if ( is_string( $Tag['Data'] ) ) { // If data is a string, use the first character $first_val = ord($Tag['Data']{0}); } else { // Otherwise use the data as is $first_val = $Tag['Data']; } // Check if the data value exists in the lookup table for this IFD entry if ( array_key_exists( $first_val, $GLOBALS[ "IFD_Tag_Definitions" ][$Tag_Definitions_Name][ $Tag["Tag Number"] ] ) ) { // Data value exists in lookup table - return the matching string return $GLOBALS[ "IFD_Tag_Definitions" ][$Tag_Definitions_Name][ $Tag["Tag Number"] ][ $first_val ]; } else { // Data value doesnt exist in lookup table - return explanation string return "Unknown Reserved value $first_val "; } } else if ( $Tag['Type'] == "Special" ) { // Format is special - interpret to text with special handlers return get_Special_Tag_Text_Value( $Tag, $Tag_Definitions_Name ); } else if ( $Tag['Type'] == "PIM" ) { // Format is Print Image Matching info - interpret with custom handler return get_PIM_Text_Value( $Tag, $Tag_Definitions_Name ); } else if ( $Tag['Type'] == "SubIFD" ) { // Format is a Sub-IFD - this has no text value return ""; } else { // Unknown Format - Couldn't interpret using the IFD_Tag_Definitions global array information return FALSE; } } /****************************************************************************** * End of Function: get_Tag_Text_Value ******************************************************************************/ /****************************************************************************** * * Internal Function: get_Special_Tag_Text_Value * * Description: Interprets an IFD entry marked as "Special" in the IFD_Tag_Definitions * global array into a text string using custom handlers * * Parameters: Tag - The IFD entry to process * Tag_Definitions_Name - The name of the tag definitions to use from within the IFD_Tag_Definitions global array * * Returns: String - if the tag was successfully decoded into a text string * FALSE - if the tag could not be decoded * ******************************************************************************/ function get_Special_Tag_Text_Value( $Tag, $Tag_Definitions_Name ) { // Check what type of IFD is being decoded if ( $Tag_Definitions_Name == "TIFF" ) { // This is a TIFF IFD (bottom level) // Check what tag number the IFD entry has. switch ( $Tag['Tag Number'] ) { case 530: // YCbCr Sub Sampling Entry // Data contains two numerical values if ( ( $Tag['Data'][0] == 2 ) && ( $Tag['Data'][1] == 1 ) ) { // Values are 2,1 - hence YCbCr 4:2:2 return "YCbCr 4:2:2 ratio of chrominance components to the luminance components"; } elseif ( ( $Tag['Data'][0] == 2 ) && ( $Tag['Data'][1] == 2 ) ) { // Values are 2,2 - hence YCbCr 4:2:0 return "YCbCr 4:2:0 ratio of chrominance components to the luminance components"; } else { // Other values are unknown return "Unknown Reserved value (" . $Tag['Data'][0] . ")"; } break; default: return FALSE; } } else if ( $Tag_Definitions_Name == "EXIF" ) { // This is an EXIF IFD // Check what tag number the IFD entry has. switch ( $Tag['Tag Number'] ) { case 37121: // Components configuration // Data contains 4 numerical values indicating component type $output_str = ""; // Cycle through each component for ( $Num = 0; $Num < 4; $Num++ ) { // Construct first part of text string $output_str .= "Component " . ( $Num + 1 ) . ": "; // Construct second part of text string via // lookup using numerical value $value = ord( $Tag['Data']{$Num} ); switch( $value ) { case 0: $output_str .= "Does not exist\n"; break; case 1: $output_str .= "Y (Luminance)\n"; break; case 2: $output_str .= "Cb (Chroma minus Blue)\n"; break; case 3: $output_str .= "Cr (Chroma minus Red)\n"; break; case 4: $output_str .= "Red\n"; break; case 5: $output_str .= "Green\n"; break; case 6: $output_str .= "Blue\n"; break; default: $output_str .= "Unknown value $value\n"; }; } // Return the completed string return $output_str; break; case 41730: // Colour Filter Array Pattern // The first two characters are a SHORT for Horizontal repeat pixel unit - $n_max = get_IFD_Data_Type( substr( $Tag['Data'], 0, 2 ), 3, $Tag['Byte Align'] ); // The next two characters are a SHORT for Vertical repeat pixel unit - $m_max = get_IFD_Data_Type( substr( $Tag['Data'], 2, 2 ), 3, $Tag['Byte Align'] ); // At least one camera type appears to have byte reversed values for N_Max and M_Max // Check if they need reversing if ( $n_max > 256 ) { $n_max = $n_max/256 + 256*($n_max%256); } if ( $m_max > 256 ) { $m_max = $m_max/256 + 256*($m_max%256); } $output_str = ""; // Cycle through all the elements in the resulting 2 dimensional array, for( $m = 1; $m <= $m_max; $m++ ) { for( $n = 1; $n <= $n_max; $n++ ) { // Append text from a lookup table according to // the value read for this element switch ( ord($Tag['Data']{($n_max*($m-1)+$n+3)}) ) { case 0: $output_str .= "RED "; break; case 1: $output_str .= "GREEN "; break; case 2: $output_str .= "BLUE "; break; case 3: $output_str .= "CYAN "; break; case 4: $output_str .= "MAGENTA "; break; case 5: $output_str .= "YELLOW "; break; case 6: $output_str .= "WHITE "; break; default: $output_str .= "Unknown "; break; }; }; $output_str .= "\n"; }; // Return the resulting string return $output_str; break; default: return FALSE; } } else { // Unknown IFD type, see if it is part of a makernote return get_Makernote_Text_Value( $Tag, $Tag_Definitions_Name ); } } /****************************************************************************** * End of Function: get_Tag_Text_Value ******************************************************************************/ /****************************************************************************** * * Function: interpret_IFD * * Description: Generates html detailing the contents a single IFD. * * Parameters: IFD_array - the array containing an IFD * filename - the name of the Image file being processed ( used * by scripts which displays EXIF thumbnails) * * Returns: output_str - A string containing the HTML * ******************************************************************************/ function interpret_IFD( $IFD_array, $filename ) { // Create the output string with the table tag $output_str = "Error - ASCII Strings should not be processed in get_IFD_Data_Type
\n"; return "Error Should never get here"; //explode( "\x00", $input_data ); } // Check if this is a Unsigned rational type elseif ( $data_type == 5 ) { // This is a Unsigned rational type // Check the byte alignment to see if the bytes need to be reversed if ( $Byte_Align == "MM" ) { // Motorola MSB first byte aligment // Unpack the Numerator and denominator and return them return unpack( 'NNumerator/NDenominator', $input_data ); } else { // Intel LSB first byte aligment // Unpack the Numerator and denominator and return them return unpack( 'VNumerator/VDenominator', $input_data ); } } // Check if this is a Signed Byte, Signed Short or Signed Long elseif ( ( $data_type == 6 ) || ( $data_type == 8 ) || ( $data_type == 9 ) ) { // This is a Signed Byte, Signed Short or Signed Long // Check the byte alignment to see if the bytes need to be reversed if ( $Byte_Align == "II" ) { //Intel format, reverse the bytes $input_data = strrev ( $input_data ); } // Convert the binary string to an Unsigned number $value = hexdec( bin2hex( $input_data ) ); // Convert to signed number // Check if it is a Byte above 128 (i.e. a negative number) if ( ( $data_type == 6 ) && ( $value > 128 ) ) { // number should be negative - make it negative return $value - 256; } // Check if it is a Short above 32767 (i.e. a negative number) if ( ( $data_type == 8 ) && ( $value > 32767 ) ) { // number should be negative - make it negative return $value - 65536; } // Check if it is a Long above 2147483648 (i.e. a negative number) if ( ( $data_type == 9 ) && ( $value > 2147483648 ) ) { // number should be negative - make it negative return $value - 4294967296; } // Return the signed number return $value; } // Check if this is Undefined type elseif ( $data_type == 7 ) { // Custom Data - Do nothing return $input_data; } // Check if this is a Signed Rational type elseif ( $data_type == 10 ) { // This is a Signed Rational type // Signed Long not available with endian in unpack , use unsigned and convert // Check the byte alignment to see if the bytes need to be reversed if ( $Byte_Align == "MM" ) { // Motorola MSB first byte aligment // Unpack the Numerator and denominator $value = unpack( 'NNumerator/NDenominator', $input_data ); } else { // Intel LSB first byte aligment // Unpack the Numerator and denominator $value = unpack( 'VNumerator/VDenominator', $input_data ); } // Convert the numerator to a signed number // Check if it is above 2147483648 (i.e. a negative number) if ( $value['Numerator'] > 2147483648 ) { // number is negative $value['Numerator'] -= 4294967296; } // Convert the denominator to a signed number // Check if it is above 2147483648 (i.e. a negative number) if ( $value['Denominator'] > 2147483648 ) { // number is negative $value['Denominator'] -= 4294967296; } // Return the Signed Rational value return $value; } // Check if this is a Float type elseif ( $data_type == 11 ) { // IEEE 754 Float // TODO - EXIF - IFD datatype Float not implemented yet return "FLOAT NOT IMPLEMENTED YET"; } // Check if this is a Double type elseif ( $data_type == 12 ) { // IEEE 754 Double // TODO - EXIF - IFD datatype Double not implemented yet return "DOUBLE NOT IMPLEMENTED YET"; } else { // Error - Invalid Datatype return "Invalid Datatype $data_type"; } } /****************************************************************************** * End of Function: get_IFD_Data_Type ******************************************************************************/ /****************************************************************************** * * Function: put_IFD_Data_Type * * Description: Encodes an IFD field from a value to a binary data string, using * information supplied about the data type and byte alignment of * the stored data. * * Parameters: input_data - an IFD data value, numeric or string * data_type - a number representing the IFD datatype as per the * TIFF 6.0 specification: * 1 = Unsigned 8-bit Byte * 2 = ASCII String * 3 = Unsigned 16-bit Short * 4 = Unsigned 32-bit Long * 5 = Unsigned 2x32-bit Rational * 6 = Signed 8-bit Byte * 7 = Undefined * 8 = Signed 16-bit Short * 9 = Signed 32-bit Long * 10 = Signed 2x32-bit Rational * 11 = 32-bit Float * 12 = 64-bit Double * Byte_Align - Indicates the byte alignment of the data. * MM = Motorola, MSB first, Big Endian * II = Intel, LSB first, Little Endian * * Returns: output - the packed binary string of the data * ******************************************************************************/ function put_IFD_Data_Type( $input_data, $data_type, $Byte_Align ) { // Process according to the datatype switch ( $data_type ) { case 1: // Unsigned Byte - return character as is return chr($input_data); break; case 2: // ASCII String // Return the string with terminating null return $input_data . "\x00"; break; case 3: // Unsigned Short // Check byte alignment if ( $Byte_Align == "II" ) { // Intel/Little Endian - pack the short and return return pack( "v", $input_data ); } else { // Motorola/Big Endian - pack the short and return return pack( "n", $input_data ); } break; case 4: // Unsigned Long // Check byte alignment if ( $Byte_Align == "II" ) { // Intel/Little Endian - pack the long and return return pack( "V", $input_data ); } else { // Motorola/Big Endian - pack the long and return return pack( "N", $input_data ); } break; case 5: // Unsigned Rational // Check byte alignment if ( $Byte_Align == "II" ) { // Intel/Little Endian - pack the two longs and return return pack( "VV", $input_data['Numerator'], $input_data['Denominator'] ); } else { // Motorola/Big Endian - pack the two longs and return return pack( "NN", $input_data['Numerator'], $input_data['Denominator'] ); } break; case 6: // Signed Byte // Check if number is negative if ( $input_data < 0 ) { // Number is negative - return signed character return chr( $input_data + 256 ); } else { // Number is positive - return character return chr( $input_data ); } break; case 7: // Unknown - return as is return $input_data; break; case 8: // Signed Short // Check if number is negative if ( $input_data < 0 ) { // Number is negative - make signed value $input_data = $input_data + 65536; } // Check byte alignment if ( $Byte_Align == "II" ) { // Intel/Little Endian - pack the short and return return pack( "v", $input_data ); } else { // Motorola/Big Endian - pack the short and return return pack( "n", $input_data ); } break; case 9: // Signed Long // Check if number is negative if ( $input_data < 0 ) { // Number is negative - make signed value $input_data = $input_data + 4294967296; } // Check byte alignment if ( $Byte_Align == "II" ) { // Intel/Little Endian - pack the long and return return pack( "v", $input_data ); } else { // Motorola/Big Endian - pack the long and return return pack( "n", $input_data ); } break; case 10: // Signed Rational // Check if numerator is negative if ( $input_data['Numerator'] < 0 ) { // Number is numerator - make signed value $input_data['Numerator'] = $input_data['Numerator'] + 4294967296; } // Check if denominator is negative if ( $input_data['Denominator'] < 0 ) { // Number is denominator - make signed value $input_data['Denominator'] = $input_data['Denominator'] + 4294967296; } // Check byte alignment if ( $Byte_Align == "II" ) { // Intel/Little Endian - pack the two longs and return return pack( "VV", $input_data['Numerator'], $input_data['Denominator'] ); } else { // Motorola/Big Endian - pack the two longs and return return pack( "NN", $input_data['Numerator'], $input_data['Denominator'] ); } break; case 11: // Float // IEEE 754 Float // TODO - EXIF - IFD datatype Float not implemented yet return "FLOAT NOT IMPLEMENTED YET"; break; case 12: // Double // IEEE 754 Double // TODO - EXIF - IFD datatype Double not implemented yet return "DOUBLE NOT IMPLEMENTED YET"; break; default: // Error - Invalid Datatype return "Invalid Datatype $data_type"; break; } // Shouldn't get here return FALSE; } /****************************************************************************** * End of Function: put_IFD_Data_Type ******************************************************************************/ /****************************************************************************** * * Function: get_IFD_value_as_text * * Description: Decodes an IFD field value from a binary data string, using * information supplied about the data type and byte alignment of * the stored data. * This function should be used for all datatypes except ASCII strings * * Parameters: input_data - a binary data string containing the IFD value, * must be exact length of the value * data_type - a number representing the IFD datatype as per the * TIFF 6.0 specification: * 1 = Unsigned 8-bit Byte * 2 = ASCII String * 3 = Unsigned 16-bit Short * 4 = Unsigned 32-bit Long * 5 = Unsigned 2x32-bit Rational * 6 = Signed 8-bit Byte * 7 = Undefined * 8 = Signed 16-bit Short * 9 = Signed 32-bit Long * 10 = Signed 2x32-bit Rational * 11 = 32-bit Float * 12 = 64-bit Double * Byte_Align - Indicates the byte alignment of the data. * MM = Motorola, MSB first, Big Endian * II = Intel, LSB first, Little Endian * * Returns: output - the value of the data (string or numeric) * ******************************************************************************/ function get_IFD_value_as_text( $Exif_Tag ) { // Create a string to receive the output text $output_str = ""; // Select Processing method according to the datatype switch ($Exif_Tag['Data Type']) { case 1 : // Unsigned Byte case 3 : // Unsigned Short case 4 : // Unsigned Long case 6 : // Signed Byte case 8 : // Signed Short case 9 : // Signed Long // Cycle through each of the values for this tag foreach ( $Exif_Tag['Data'] as $val ) { // Check that this isn't the first value, if ( $output_str != "" ) { // This isn't the first value, Add a Comma and Newline to the output $output_str .= ",\n"; } // Add the Value to the output $output_str .= $val; } break; case 2 : // ASCII // Append all the strings together, separated by Newlines $output_str .= implode ( "\n", $Exif_Tag['Data']); break; case 5 : // Unsigned Rational case 10: // Signed Rational // Cycle through each of the values for this tag foreach ( $Exif_Tag['Data'] as $val ) { // Check that this isn't the first value, if ( $output_str != "" ) { // This isn't the first value, Add a Comma and Newline to the output $output_str .= ",\n"; } // Add the Full Value to the output $output_str .= $val['Numerator'] ."/" . $val['Denominator']; // Check if division by zero might be a problem if ( $val['Denominator'] != 0 ) { // Denominator is not zero, Add the Decimal Value to the output text $output_str .= " (" . ($val['Numerator'] / $val['Denominator']) . ")"; } } break; case 11: // Float case 12: // Double // TODO - EXIF - IFD datatype Double and Float not implemented yet $output_str .= "Float and Double not implemented yet"; break; case 7 : // Undefined // Unless the User has asked to see the raw binary data, this // type should not be displayed // Check if the user has requested to see the binary data in hex if ( $GLOBALS['SHOW_BINARY_DATA_HEX'] == TRUE) { // User has requested to see the binary data in hex // Add the value in hex $output_str .= "( " . strlen( $Exif_Tag['Data'] ) . " bytes of binary data ): " . bin2hex( $Exif_Tag['Data'] ) ; } // Check if the user has requested to see the binary data as is else if ( $GLOBALS['SHOW_BINARY_DATA_TEXT'] == TRUE) { // User has requested to see the binary data as is // Add the value as is $output_str .= "( " . strlen( $Exif_Tag['Data'] ) . " bytes of binary data ): " . $Exif_Tag['Data'] ; } else { // User has NOT requested to see binary data, // Add a message indicating the number of bytes to the output $output_str .= "( " . strlen( $Exif_Tag['Data'] ) . " bytes of binary data ) " ; } break; default : // Error - Unknown IFD datatype $output_str .= "Error - Exif tag data type (" . $Exif_Tag['Data Type'] .") is invalid"; break; } // Return the resulting text string return $output_str; } /****************************************************************************** * End of Function: get_IFD_value_as_text ******************************************************************************/ /****************************************************************************** * Global Variable: IFD_Data_Sizes * * Contents: The sizes (in bytes) of each EXIF IFD Datatype, indexed by * their datatype number * ******************************************************************************/ $GLOBALS['IFD_Data_Sizes'] = array( 1 => 1, // Unsigned Byte 2 => 1, // ASCII String 3 => 2, // Unsigned Short 4 => 4, // Unsigned Long 5 => 8, // Unsigned Rational 6 => 1, // Signed Byte 7 => 1, // Undefined 8 => 2, // Signed Short 9 => 4, // Signed Long 10 => 8, // Signed Rational 11 => 4, // Float 12 => 8 ); // Double /****************************************************************************** * End of Global Variable: IFD_Data_Sizes ******************************************************************************/ ?>