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

SourceForge.net Logo Documentation generated on Wed, 21 Jul 2004 19:13:08 +0200 by phpDocumentor 1.3.0RC3