Source for file PelWrap.php

Documentation is available at PelWrap.php

  1. <?php
  2.  
  3. /**
  4.  * Wrapper for the PEL library
  5.  * 
  6.  * This module simplifies usage of PEL - a PHP Exif Library.
  7.  */ 
  8. class PelWrap extends Module {
  9.     /**
  10.      * @var string Path to Pel library
  11.      */
  12.     var $path = '';
  13.     
  14.     /**
  15.      * Constructor for the Pel module
  16.      * 
  17.      * Initialize members
  18.      */
  19.     function PelWrap({
  20.         $this->register_error('ERROR_PEL_LIBRARY_NOT_FOUND',
  21.             "Can not find Pel library at: '%s'.""ERROR");
  22.     }
  23.     
  24.     /**
  25.      * Get the configuration from the config file
  26.      */
  27.     function get_configuration({
  28.         // Load values from config file if applicable
  29.         if (isset($this->application->config['pel'])) {
  30.             $keys explode(' ''path');
  31.             foreach ($keys as $key)
  32.                 if (isset_and_non_empty($this->application->config['pel'][$key]))
  33.                     $this->$key $this->application->config['pel'][$key];
  34.         }
  35.         
  36.         // Check if Pel library files exist
  37.         if (!file_exists($this->path))
  38.             $this->error->display_error('ERROR_PEL_LIBRARY_NOT_FOUND'$this->path);
  39.     }
  40.     
  41.     /**
  42.      * Setup the Pel module
  43.      * 
  44.      * Call this action before opening and processing files
  45.      */
  46.     function setup({
  47.         // Load configuration
  48.         $this->get_configuration();
  49.         
  50.         // Load the Pel library
  51.         require_once($this->path . '/PelJpeg.php');
  52.     }
  53.  
  54.     /**
  55.      * Open an image using PEL
  56.      * 
  57.      * @param string $image_file Path to the image file
  58.      */
  59.     function open($image_file{
  60.         if ($this->path == ''$this->setup();
  61.         
  62.         return new PelJpeg($image_file);
  63.     }
  64.     
  65.     /**
  66.      * Update an image file
  67.      * 
  68.      * @param string $image_file Path to the image file
  69.      */
  70.     function update($image_file$pelobj{
  71.         file_put_contents($image_file$pelobj->getBytes());
  72.     }
  73.     
  74.     /**
  75.      * Get or set the value of a tag
  76.      * 
  77.      * @param string $image_file Path to the image file
  78.      * @param string $tag An Exif tag as per the Pel documentation (http://pel.sourceforge.net/doc/PEL/PelTag.html)
  79.      * @param string $new_value The value to set the tag to (if skipped, the tag remains unchanged)
  80.      * 
  81.      * @return string Returns the value of the tag
  82.      */
  83.     function access($image_file$tag$new_value=null{
  84.         // Value to return
  85.         $returned '';
  86.         
  87.         // Open file if not already open
  88.         $pelobj $this->open($image_file);
  89.         if ($pelobj == nullreturn $returned;
  90.         
  91.         // List of subIfds
  92.         $sub array(PelIfd::EXIFPelIfd::GPSPelIfd::INTEROPERABILITY);
  93.         
  94.         // Get Exif section
  95.         $exif $pelobj->getExif();
  96.         if ($exif == nullreturn $returned;
  97.         
  98.         // Get Tiff chunk
  99.         $tiff $exif->getTiff();
  100.         if ($tiff == nullreturn $returned;
  101.         
  102.         // Search through Ifds and subIfds
  103.         $ifd $tiff->getIfd();
  104.         while ($ifd != null{
  105.             $entry $ifd->getEntry(constant("PelTag::$tag"));
  106.             if ($entry == null{
  107.                 foreach ($sub as $s{
  108.                     $ifds $ifd->getSubIfd($s);
  109.                     if ($ifds != null{
  110.                         $entry $ifds->getEntry(constant("PelTag::$tag"));
  111.                         if ($entry != nullbreak;
  112.                     }
  113.                 }
  114.                 if ($entry != nullbreak;
  115.             else
  116.                 break;
  117.             $ifd $ifd->getNextIfd();
  118.         }
  119.  
  120.         if ($entry == nullreturn $returned;
  121.         
  122.         // Set a value as needed
  123.         if ($value != null{
  124.             $entry->setValue($new_value);
  125.             $this->update($image_file$pelobj);
  126.         }        
  127.         
  128.         return $entry->getValue();
  129.     }
  130. }
  131.  
  132. ?>

Documentation generated on Sat, 23 Jun 2007 21:28:21 -0500 by phpDocumentor 1.3.2