Source for file PelExif.php

Documentation is available at PelExif.php

  1. <?php
  2.  
  3. /*  PEL: PHP Exif Library.  A library with support for reading and
  4.  *  writing all Exif headers in JPEG and TIFF images using PHP.
  5.  *
  6.  *  Copyright (C) 2004, 2005  Martin Geisler.
  7.  *
  8.  *  This program is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2 of the License, or
  11.  *  (at your option) any later version.
  12.  *
  13.  *  This program is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with this program in the file COPYING; if not, write to the
  20.  *  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  21.  *  Boston, MA 02110-1301 USA
  22.  */
  23.  
  24. /* $Id$ */
  25.  
  26.  
  27. /**
  28.  * Classes for dealing with Exif data.
  29.  *
  30.  * @author Martin Geisler <mgeisler@users.sourceforge.net>
  31.  * @version $Revision$
  32.  * @date $Date$
  33.  * @license http://www.gnu.org/licenses/gpl.html GNU General Public
  34.  *  License (GPL)
  35.  * @package PEL
  36.  */
  37.  
  38. /**#@+ Required class definitions. */
  39. require_once('PelJpegContent.php');
  40. require_once('PelException.php');
  41. require_once('PelFormat.php');
  42. require_once('PelEntry.php');
  43. require_once('PelTiff.php');
  44. require_once('PelIfd.php');
  45. require_once('PelTag.php');
  46. require_once('Pel.php');
  47. /**#@-*/
  48.  
  49.  
  50. /**
  51.  * Class representing Exif data.
  52.  *
  53.  * Exif data resides as {@link PelJpegContent data} and consists of a
  54.  * header followed by a number of {@link PelJpegIfd IFDs}.
  55.  *
  56.  * The interesting method in this class is {@link getTiff()} which
  57.  * will return the {@link PelTiff} object which really holds the data
  58.  * which one normally think of when talking about Exif data.  This is
  59.  * because Exif data is stored as an extension of the TIFF file
  60.  * format.
  61.  *
  62.  * @author Martin Geisler <mgeisler@users.sourceforge.net>
  63.  * @package PEL
  64.  */
  65. class PelExif extends PelJpegContent {
  66.  
  67.   /**
  68.    * Exif header.
  69.    *
  70.    * The Exif data must start with these six bytes to be considered
  71.    * valid.
  72.    */
  73.   const EXIF_HEADER = "Exif\0\0";
  74.  
  75.   /**
  76.    * The PelTiff object contained within.
  77.    *
  78.    * @var PelTiff 
  79.    */
  80.   private $tiff null;
  81.  
  82.  
  83.   /**
  84.    * Construct a new Exif object.
  85.    *
  86.    * The new object will be empty --- use the {@link load()} method to
  87.    * load Exif data from a {@link PelDataWindow} object, or use the
  88.    * {@link setTiff()} to change the {@link PelTiff} object, which is
  89.    * the true holder of the Exif {@link PelEntry entries}.
  90.    */
  91.   function __construct({
  92.  
  93.   }
  94.  
  95.  
  96.   /**
  97.    * Load and parse Exif data.
  98.    *
  99.    * This will populate the object with Exif data, contained as a
  100.    * {@link PelTiff} object.  This TIFF object can be accessed with
  101.    * the {@link getTiff()} method.
  102.    */
  103.   function load(PelDataWindow $d{
  104.     Pel::debug('Parsing %d bytes of Exif data...'$d->getSize());
  105.  
  106.     /* There must be at least 6 bytes for the Exif header. */
  107.     if ($d->getSize(6)
  108.       throw new PelInvalidDataException('Expected at least 6 bytes of Exif ' .
  109.                                         'data, found just %d bytes.',
  110.                                         $d->getSize());
  111.     
  112.     /* Verify the Exif header */
  113.     if ($d->strcmp(0self::EXIF_HEADER)) {
  114.       $d->setWindowStart(strlen(self::EXIF_HEADER));
  115.     else {
  116.       throw new PelInvalidDataException('Exif header not found.');
  117.     }
  118.  
  119.     /* The rest of the data is TIFF data. */
  120.     $this->tiff new PelTiff();
  121.     $this->tiff->load($d);
  122.   }
  123.  
  124.  
  125.   /**
  126.    * Change the TIFF information.
  127.    *
  128.    * Exif data is really stored as TIFF data, and this method can be
  129.    * used to change this data from one {@link PelTiff} object to
  130.    * another.
  131.    *
  132.    * @param PelTiff the new TIFF object.
  133.    */
  134.   function setTiff(PelTiff $tiff{
  135.     $this->tiff $tiff;
  136.   }
  137.  
  138.  
  139.   /**
  140.    * Get the underlying TIFF object.
  141.    *
  142.    * The actual Exif data is stored in a {@link PelTiff} object, and
  143.    * this method provides access to it.
  144.    *
  145.    * @return PelTiff the TIFF object with the Exif data.
  146.    */
  147.   function getTiff({
  148.     return $this->tiff;
  149.   }
  150.  
  151.  
  152.   /**
  153.    * Produce bytes for the Exif data.
  154.    *
  155.    * @return string bytes representing this object.
  156.    */
  157.   function getBytes({
  158.     return self::EXIF_HEADER $this->tiff->getBytes();
  159.   }
  160.  
  161.   
  162.   /**
  163.    * Return a string representation of this object.
  164.    *
  165.    * @return string a string describing this object.  This is mostly
  166.    *  useful for debugging.
  167.    */
  168.   function __toString({
  169.     return Pel::tra("Dumping Exif data...\n".
  170.       $this->tiff->__toString();
  171.   }
  172.  
  173. }
  174.  
  175. ?>

Documentation generated on Thu, 05 May 2011 07:19:10 +0200 by phpDocumentor 1.4.3