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 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., 59 Temple Place, Suite 330,
  21. * Boston, MA 02111-1307 USA
  22. */
  23.  
  24. /* PelExif.php,v 1.11 2005/02/11 20:43:41 gimpster Exp */
  25.  
  26.  
  27. /**
  28. * Classes for dealing with EXIF data.
  29. *
  30. * @author Martin Geisler <gimpster@users.sourceforge.net>
  31. * @version 1.11
  32. * @date 2005/02/11 20:43:41
  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. ('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. /**#@-*/ * Class representing EXIF data.
  48. *
  49. * EXIF data resides as {@link PelJpegContent data} and consists of a
  50. * header followed by a number of {@link PelJpegIfd IFDs}.
  51. *
  52. * The interesting method in this class is {@link getTiff()} which
  53. * will return the {@link PelTiff} object which really holds the data
  54. * which one normally think of when talking about EXIF data. This is
  55. * because EXIF data is stored as an extension of the TIFF file
  56. * format.
  57. *
  58. * @author Martin Geisler <gimpster@users.sourceforge.net>
  59. * @package PEL
  60. */
  61. class PelExif extends PelJpegContent {
  62.  
  63. /**
  64. * EXIF header.
  65. *
  66. * The EXIF data must start with these six bytes to be considered
  67. * valid.
  68. */
  69. const EXIF_HEADER = "Exif\0\0";
  70.  
  71. /**
  72. * The PelTiff object contained within.
  73. *
  74. * @var PelTiff
  75. */
  76. private $tiff = null;
  77.  
  78.  
  79. /**
  80. * Construct a new EXIF object.
  81. *
  82. * The new object will be empty --- use the {@link load()} method to
  83. * load EXIF data from a {@link PelDataWindow} object, or use the
  84. * {@link setTiff()} to change the {@link PelTiff} object, which is
  85. * the true holder of the EXIF {@link PelEntry entries}.
  86. */
  87. function __construct() {
  88.  
  89. }
  90.  
  91.  
  92. /**
  93. * Load and parse EXIF data.
  94. *
  95. * This will populate the object with EXIF data, contained as a
  96. * {@link PelTiff} object. This TIFF object can be accessed with
  97. * the {@link getTiff()} method.
  98. */
  99. function load(PelDataWindow $d) {
  100. Pel::debug('Parsing %d bytes of EXIF data...', $d->getSize());
  101.  
  102. /* There must be at least 6 bytes for the EXIF header. */
  103. if ($d->getSize() < 6)
  104. throw new PelInvalidDataException('Expected at least 6 bytes of EXIF ' .
  105. 'data, found just %d bytes.',
  106. $d->getSize());
  107. /* Verify the EXIF header */
  108. if ($d->strcmp(0, self::EXIF_HEADER)) {
  109. $d->setWindowStart(6);
  110. } else {
  111. throw new PelInvalidDataException('EXIF header not found.');
  112. }
  113.  
  114. /* The rest of the data is TIFF data. */
  115. $this->tiff = new PelTiff();
  116. $this->tiff->load($d);
  117. }
  118.  
  119.  
  120. /**
  121. * Change the TIFF information.
  122. *
  123. * EXIF data is really stored as TIFF data, and this method can be
  124. * used to change this data from one {@link PelTiff} object to
  125. * another.
  126. *
  127. * @param PelTiff the new TIFF object.
  128. */
  129. function setTiff(PelTiff $tiff) {
  130. $this->tiff = $tiff;
  131. }
  132.  
  133.  
  134. /**
  135. * Get the underlying TIFF object.
  136. *
  137. * The actual EXIF data is stored in a {@link PelTiff} object, and
  138. * this method provides access to it.
  139. *
  140. * @return PelTiff the TIFF object with the EXIF data.
  141. */
  142. function getTiff() {
  143. return $this->tiff;
  144. }
  145.  
  146.  
  147. /**
  148. * Produce bytes for this object.
  149. *
  150. * @return string bytes representing this object. These bytes will
  151. * match the bytes given to {@link __construct the constructor}.
  152. */
  153. function getBytes() {
  154. return self::EXIF_HEADER . $this->tiff->getbytes();
  155. }
  156.  
  157. /**
  158. * Return a string representation of this object.
  159. *
  160. * @return string a string describing this object. This is mostly
  161. * useful for debugging.
  162. */
  163. function __toString() {
  164. return Pel::tra("Dumping EXIF data...\n") .
  165. $this->tiff->__toString();
  166. }
  167.  
  168. }
  169.  
  170. ?>

SourceForge.net Logo Documentation generated on Fri, 18 Feb 2005 01:43:17 +0100 by phpDocumentor 1.3.0RC3