[ PHPXref.com ] [ Generated: Sun Jul 20 19:44:41 2008 ] [ PHP JPEG Metadata 1.11 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> PIM.php (source)

   1  <?php
   2  
   3  /******************************************************************************

   4  *

   5  * Filename:     PIM.php

   6  *

   7  * Description:  Provides functions for reading, writing and interpreting a

   8  *               Print Image Matching information data block.

   9  *

  10  * Author:       Evan Hunter

  11  *

  12  * Date:         23/7/2004

  13  *

  14  * Project:      PHP JPEG Metadata Toolkit

  15  *

  16  * Revision:     1.00

  17  *

  18  * URL:          http://electronics.ozhiker.com

  19  *

  20  * Copyright:    Copyright Evan Hunter 2004

  21  *

  22  * License:      This file is part of the PHP JPEG Metadata Toolkit.

  23  *

  24  *               The PHP JPEG Metadata Toolkit is free software; you can

  25  *               redistribute it and/or modify it under the terms of the

  26  *               GNU General Public License as published by the Free Software

  27  *               Foundation; either version 2 of the License, or (at your

  28  *               option) any later version.

  29  *

  30  *               The PHP JPEG Metadata Toolkit is distributed in the hope

  31  *               that it will be useful, but WITHOUT ANY WARRANTY; without

  32  *               even the implied warranty of MERCHANTABILITY or FITNESS

  33  *               FOR A PARTICULAR PURPOSE.  See the GNU General Public License

  34  *               for more details.

  35  *

  36  *               You should have received a copy of the GNU General Public

  37  *               License along with the PHP JPEG Metadata Toolkit; if not,

  38  *               write to the Free Software Foundation, Inc., 59 Temple

  39  *               Place, Suite 330, Boston, MA  02111-1307  USA

  40  *

  41  *               If you require a different license for commercial or other

  42  *               purposes, please contact the author: evan@ozhiker.com

  43  *

  44  ******************************************************************************/
  45  
  46  
  47  include_once  "EXIF.php";
  48  
  49  // TODO Find out definitions of Print Image Matching Info tags

  50  
  51  
  52  /******************************************************************************

  53  *

  54  * Function:     Decode_PIM

  55  *

  56  * Description:  Decodes the contents of a EXIF tag containing Print Image

  57  *               Matching information, and returns the contents as an array

  58  *

  59  * Parameters:   tag - An EXIF tag containing Print Image Matching information

  60  *                     as from get_EXIF_JPEG

  61  *               Tag_Definitions_Name - The name of the Tag Definitions group

  62  *                                      within the global array IFD_Tag_Definitions

  63  *

  64  * Returns:      newtag - The EXIF tag, modified with the data field containing

  65  *                        an array of the PIM contents

  66  *

  67  ******************************************************************************/
  68  
  69  function Decode_PIM( $tag, $Tag_Definitions_Name )
  70  {
  71  
  72          // Create a new EXIF tag for the output

  73          $newtag = $tag;
  74  
  75          // Check that this tag is for Print Image Matching Info

  76          if ( $tag['Type'] == "PIM" )
  77          {
  78  
  79                  // Check that the data starts with PrintIM

  80                  if ( substr( $tag['Data'], 0, 8 ) == "PrintIM\x00" )
  81                  {
  82  
  83                          // Find the end of the version string

  84                          if ( ( $ver_pos = strpos ( $tag['Data'], "\0", 8 ) ) == -1 )
  85                          {
  86                                  // couldn't find the start of the version string

  87                                  return $newtag;
  88                          }
  89                          
  90                          // Create an array to receive the Data

  91                          $newtag['Data'] = array( );
  92  
  93                          // Extract the PrintIM version

  94                          $newtag['Data']['Version'] = substr( $tag['Data'], 8, $ver_pos - 8 );
  95                          // Skip the position over the version

  96                          $count_pos =  $ver_pos+2;
  97                          
  98                          // Extract the count of tags - 2 bytes

  99                          $PI_tag_count = get_IFD_Data_Type( substr($tag['Data'], $count_pos, 2) , 3, $tag['Byte Align'] );
 100  
 101                          // Panasonic have put an extra Null after the Version, which

 102                          // causes the tag count to be wrong -

 103                          // check if it is zero - i.e. possibly wrong

 104                          if ( ( $PI_tag_count == 0 ) )
 105                          {
 106                                  // Tag count is zero - try moving the position by one,

 107                                  // then re-extracting the count

 108                                  $count_pos++;
 109                                  $PI_tag_count = get_IFD_Data_Type( substr($tag['Data'], $count_pos, 2) , 3, $tag['Byte Align'] );
 110                          }
 111  
 112                          // Extract the data part of the PrintIM block

 113                          $data_part = substr($tag['Data'], $count_pos+2);
 114  
 115                          // Cycle through each tag

 116                          for ( $a = 0; $a < $PI_tag_count; $a++ )
 117                          {
 118                                  // Read the tag number - 2 bytes

 119                                  $PI_tag = get_IFD_Data_Type( substr($data_part, $a*6, 2) , 3, $tag['Byte Align'] );
 120                                  
 121                                  // Read the tag data - 4 bytes

 122                                  $newtag['Data'][ ] = array( 'Tag Number' => $PI_tag, 'Data' => substr($data_part, $a*6+2, 4) , 'Decoded' => False );
 123                          }
 124                  }
 125                  
 126          }
 127  
 128          // Return the updated tag

 129          return $newtag;
 130          
 131  }
 132  
 133  /******************************************************************************

 134  * End of Function:     Decode_PIM

 135  ******************************************************************************/
 136  
 137  
 138  
 139  
 140  /******************************************************************************

 141  *

 142  * Function:     Encode_PIM

 143  *

 144  * Description:  Encodes the contents of a EXIF tag containing Print Image

 145  *               Matching information, and returns the contents as a packed binary string

 146  *

 147  * Parameters:   tag - An EXIF tag containing Print Image Matching information

 148  *                     as from get_EXIF_JPEG

 149  *               Byte_Align - the Byte alignment to use - "MM" or "II"

 150  *

 151  * Returns:      packed_data - The packed binary string representing the PIM data

 152  *

 153  ******************************************************************************/
 154  
 155  function Encode_PIM( $tag, $Byte_Align)
 156  {
 157  
 158          // Create a string to receive the packed data

 159          $packed_data = "";
 160  
 161          // Check that this tag is for Print Image Matching Info

 162          if ( $tag['Type'] == "PIM" )
 163          {
 164                  // Check that the tag has been decoded - otherwise we don't need to do anything

 165                  if ( ( is_array( $tag['Data'] ) ) &&
 166                       ( count ( $tag['Data'] ) > 0 ) )
 167                  {
 168                          // Add the header to the packed data

 169                          $packed_data .= "PrintIM\x00";
 170                          
 171                          // Add the version to the packed data

 172                          $packed_data .= $tag['Data']['Version'] . "\x00";
 173  
 174                          // Create a string to receive the tag data

 175                          $tag_data_str = "";
 176                          
 177                          // Cycle through each tag

 178                          $tag_count = 0;
 179                          foreach( $tag['Data'] as $key => $curr_tag )
 180                          {
 181                                  // Make sure this is a tag and not supplementary info

 182                                  if ( is_numeric( $key ) )
 183                                  {
 184                                          // Count how many tags are created

 185                                          $tag_count++;
 186  
 187                                          // Add the tag number to the packed tag data

 188                                          $tag_data_str .= put_IFD_Data_Type( $curr_tag['Tag Number'], 3, $Byte_Align );
 189  
 190                                          // Add the tag data to the packed tag data

 191                                          $tag_data_str .= $curr_tag['Data'];
 192                                  }
 193                          }
 194                          
 195                          // Add the tag count to the packed data

 196                          $packed_data .= put_IFD_Data_Type( $tag_count, 3, $Byte_Align );
 197                          
 198                          // Add the packed tag data to the packed data

 199                          $packed_data .= $tag_data_str;
 200                  }
 201          }
 202                          
 203          // Return the resulting packed data

 204          return $packed_data;
 205  
 206  }
 207  
 208  /******************************************************************************

 209  * End of Function:     Encode_PIM

 210  ******************************************************************************/
 211  
 212  
 213  
 214  
 215  
 216  
 217  
 218  
 219  
 220  
 221  /******************************************************************************

 222  *

 223  * Function:     get_PIM_Text_Value

 224  *

 225  * Description:  Interprets the contents of a EXIF tag containing Print Image

 226  *               Matching information, and returns content as as a text string

 227  *

 228  * Parameters:   tag - An EXIF tag containing Print Image Matching information

 229  *                     as from get_EXIF_JPEG

 230  *               Tag_Definitions_Name - The name of the Tag Definitions group

 231  *                                      within the global array IFD_Tag_Definitions

 232  *

 233  * Returns:      output_str - The text string representing the PIM info

 234  *

 235  ******************************************************************************/
 236  
 237  function get_PIM_Text_Value( $Tag, $Tag_Definitions_Name )
 238  {
 239  
 240          // Create a string to receive the output

 241          $output_str = "";
 242          
 243          // Check if the PIM tag has been decoded

 244          if ( ( is_array( $Tag['Data'] ) ) &&
 245               ( count ( $Tag['Data'] ) > 0 ) )
 246          {
 247                  // The tag has been decoded

 248  
 249                  // Add the Version to the output

 250                  $output_str = "Version: " . $Tag['Data']['Version'] . "\n";
 251                  
 252                  // Check if the user wants to hide unknown tags

 253                  if ( $GLOBALS['HIDE_UNKNOWN_TAGS'] == FALSE )
 254                  {
 255                          // The user wants to see unknown tags

 256                          // Cycle through each tag

 257                          foreach ( $Tag['Data'] as $PIM_tag_Key => $PIM_tag )
 258                          {
 259                                  // Check that the tag is not the version array element

 260                                  if ( $PIM_tag_Key !== 'Version' )
 261                                  {
 262                                          // Add the tag to the output

 263                                          $output_str .= "Unknown Tag " . $PIM_tag['Tag Number'] . ": (" . strlen( $PIM_tag['Data'] ) . " bytes of data)\n";
 264                                  }
 265                          }
 266                  }
 267          }
 268          
 269          // Return the output text

 270          return $output_str;
 271  }
 272  
 273  /******************************************************************************

 274  * End of Function:     get_PIM_Text_Value

 275  ******************************************************************************/
 276  
 277  
 278  
 279  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]