Suggested php code to read file rating set by Adobe Bridge CS3

1k views Asked by At

Background: I have been attempting to read the rating that is assigned in Adobe Bridge CS3 using the creative commons Metadata toolkit for php without success. I am using shared hosting so I do not have an oppotunity to recompile php with different modules.

Is php code available that could be used to read the rating that is embedded in the .jpg file? I have read that this is an xmp (xml) formatted section within the file.

2

There are 2 answers

1
DarwinIcesurfer On BEST ANSWER

I'm posting my solution here in case someone else has a similiar problem and reads this thread. Here is what I found:
Windows Vista add the rating to the exif section embedded in the file
Adobe Bridge adds another section to the jpg file that contains data formatted in xml. The xml + data structure is referred to as the xmp file. I hadn't yet processed the file with Adobe bridge, that is why I was unable to read the xmp data with the Metadata toolkit.

Using the Creative Commons - Metadata toolkit I was able to read the ratings using the following code. This code is part of a Drupal Module, some of the referenced variables are Drupal settings: variable_get() is a Drupal function to read a variable from a perssistent data store.

include_once("PHP_JPEG_Metadata_Toolkit_1.11/JPEG.php");
  include_once("PHP_JPEG_Metadata_Toolkit_1.11/Photoshop_File_Info.php");
  include_once("PHP_JPEG_Metadata_Toolkit_1.11/EXIF.php");
  include_once("PHP_JPEG_Metadata_Toolkit_1.11/XMP.php");

  $photodir = variable_get('rotate_images_sourcefiles_dir',"sites/default/files/imageNodes");

  $rating_threshold = variable_get('rotate_images_rating_threshold',3);
  $allImages=dir($photodir);
  $filenames = scandir($photodir);

  foreach($filenames as $filename){

    $rating = null;
    $info = pathinfo($filename);
    if (strtolower($info['extension'])=="jpg"){
      //  First try to get the rating from the EXIF data, this is where it is stored by Windows Vista
      $exif = get_EXIF_JPEG( $photodir . "/" . $filename );
      $rating = $exif[0][18246]['Data'][0];

      $jpeg_header = get_jpeg_header_data($photodir . "/" . $filename );
      //  If no rating was found in the EXIF data, it may be in the Adobe format xmp section
      if ($rating == null){
        if($jpeg_header != false){
          $xmp = get_XMP_text($jpeg_header);
          $xmpArray = read_XMP_array_from_text($xmp);
          $rating = $xmpArray[0]['children'][0]['children'][0][attributes]['xap:Rating'];
        }   
      }
    }
  }

I did need to modify the EXIF_Tags.php file in the metadata toolkit by adding an additional entry to the EXIF Tags array. I reported this to the author, but I don't believe he is maintaing the module any longer. The source is on sourceforge, but I don't know how to post a patch. So you may need to make the change to EXIF.php yourself to make the code work.

'EXIF' => array (

// Exif IFD

18246 => array ( 'Name' => "Rating",
                'Type' => "Numeric" ), 
0
prodigitalson On

Theoretically if you use fgets you should be able to read it. It would be helpful if you know where this section begins in terms of bytes into the file.