senses-designertravelv3 /public_html/slir/pel-0.9.2/src/PelEntry.php

Language PHP Lines 382
MD5 Hash 526a7bd8f98c0c87f0acbfa4d229fb08 Estimated Cost $1,805 (why?)
Repository https://bitbucket.org/matyhaty/senses-designertravelv3 View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php

/*  PEL: PHP Exif Library.  A library with support for reading and
 *  writing all Exif headers in JPEG and TIFF images using PHP.
 *
 *  Copyright (C) 2004, 2005, 2006  Martin Geisler.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program in the file COPYING; if not, write to the
 *  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 *  Boston, MA 02110-1301 USA
 */

/* $Id$ */


/**
 * Classes for dealing with Exif entries.
 *
 * This file defines two exception classes and the abstract class
 * {@link PelEntry} which provides the basic methods that all Exif
 * entries will have.  All Exif entries will be represented by
 * descendants of the {@link PelEntry} class --- the class itself is
 * abstract and so it cannot be instantiated.
 *
 * @author Martin Geisler <mgeisler@users.sourceforge.net>
 * @version $Revision$
 * @date $Date$
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public
 * License (GPL)
 * @package PEL
 */

/**#@+ Required class definitions. */
require_once('PelException.php');
require_once('PelFormat.php');
require_once('PelTag.php');
require_once('Pel.php');
/**#@-*/


/**
 * Exception indicating a problem with an entry.
 *
 * @author Martin Geisler <mgeisler@users.sourceforge.net>
 * @package PEL
 * @subpackage Exception
 */
class PelEntryException extends PelException {

  /**
   * The IFD type (if known).
   *
   * @var int
   */
  protected $type;

  /**
   * The tag of the entry (if known).
   *
   * @var PelTag
   */
  protected $tag;

  /**
   * Get the IFD type associated with the exception.
   *
   * @return int one of {@link PelIfd::IFD0}, {@link PelIfd::IFD1},
   * {@link PelIfd::EXIF}, {@link PelIfd::GPS}, or {@link
   * PelIfd::INTEROPERABILITY}.  If no type is set, null is returned.
   */
  function getIfdType() {
    return $this->type;
  }


  /**
   * Get the tag associated with the exception.
   *
   * @return PelTag the tag.  If no tag is set, null is returned.
   */
  function getTag() {
    return $this->tag;
  }

}


/**
 * Exception indicating that an unexpected format was found.
 *
 * The documentation for each tag in {@link PelTag} will detail any
 * constrains.
 *
 * @author Martin Geisler <mgeisler@users.sourceforge.net>
 * @package PEL
 * @subpackage Exception
 */
class PelUnexpectedFormatException extends PelEntryException {

  /**
   * Construct a new exception indicating an invalid format.
   *
   * @param int the type of IFD.
   *
   * @param PelTag the tag for which the violation was found.
   *
   * @param PelFormat the format found.
   *
   * @param PelFormat the expected format.
   */
  function __construct($type, $tag, $found, $expected) {
    parent::__construct('Unexpected format found for %s tag: PelFormat::%s. ' .
                        'Expected PelFormat::%s instead.',
                        PelTag::getName($type, $tag),
                        strtoupper(PelFormat::getName($found)),
                        strtoupper(PelFormat::getName($expected)));
    $this->tag  = $tag;
    $this->type = $type;
  }
}


/**
 * Exception indicating that an unexpected number of components was
 * found.
 *
 * Some tags have strict limits as to the allowed number of
 * components, and this exception is thrown if the data violates such
 * a constraint.  The documentation for each tag in {@link PelTag}
 * explains the expected number of components.
 *
 * @author Martin Geisler <mgeisler@users.sourceforge.net>
 * @package PEL
 * @subpackage Exception
 */
class PelWrongComponentCountException extends PelEntryException {

  /**
   * Construct a new exception indicating a wrong number of
   * components.
   *
   * @param int the type of IFD.
   *
   * @param PelTag the tag for which the violation was found.
   *
   * @param int the number of components found.
   *
   * @param int the expected number of components.
   */
  function __construct($type, $tag, $found, $expected) {
    parent::__construct('Wrong number of components found for %s tag: %d. ' .
                        'Expected %d.',
                        PelTag::getName($type, $tag), $found, $expected);
    $this->tag  = $tag;
    $this->type = $type;
  }
}


/**
 * Common ancestor class of all {@link PelIfd} entries.
 *
 * As this class is abstract you cannot instantiate objects from it.
 * It only serves as a common ancestor to define the methods common to
 * all entries.  The most important methods are {@link getValue()} and
 * {@link setValue()}, both of which is abstract in this class.  The
 * descendants will give concrete implementations for them.
 *
 * If you have some data coming from an image (some raw bytes), then
 * the static method {@link newFromData()} is helpful --- it will look
 * at the data and give you a proper decendent of {@link PelEntry}
 * back.
 *
 * If you instead want to have an entry for some data which take the
 * form of an integer, a string, a byte, or some other PHP type, then
 * don't use this class.  You should instead create an object of the
 * right subclass ({@link PelEntryShort} for short integers, {@link
 * PelEntryAscii} for strings, and so on) directly.
 *
 * @author Martin Geisler <mgeisler@users.sourceforge.net>
 * @package PEL
 */
abstract class PelEntry {

  /**
   * Type of IFD containing this tag.
   *
   * This must be one of the constants defined in {@link PelIfd}:
   * {@link PelIfd::IFD0} for the main image IFD, {@link PelIfd::IFD1}
   * for the thumbnail image IFD, {@link PelIfd::EXIF} for the Exif
   * sub-IFD, {@link PelIfd::GPS} for the GPS sub-IFD, or {@link
   * PelIfd::INTEROPERABILITY} for the interoperability sub-IFD.
   *
   * @var int
   */
  protected $ifd_type;

  /**
   * The bytes representing this entry.
   *
   * Subclasses must either override {@link getBytes()} or, if
   * possible, maintain this property so that it always contains a
   * true representation of the entry.
   *
   * @var string
   */
  protected $bytes = '';

  /**
   * The {@link PelTag} of this entry.
   *
   * @var PelTag
   */
  protected $tag;

  /**
   * The {@link PelFormat} of this entry.
   *
   * @var PelFormat
   */
  protected $format;

  /**
   * The number of components of this entry.
   *
   * @var int
   */
  protected $components;


  /**
   * Return the tag of this entry.
   *
   * @return PelTag the tag of this entry.
   */
  function getTag() {
    return $this->tag;
  }


  /**
   * Return the type of IFD which holds this entry.
   *
   * @return int one of the constants defined in {@link PelIfd}:
   * {@link PelIfd::IFD0} for the main image IFD, {@link PelIfd::IFD1}
   * for the thumbnail image IFD, {@link PelIfd::EXIF} for the Exif
   * sub-IFD, {@link PelIfd::GPS} for the GPS sub-IFD, or {@link
   * PelIfd::INTEROPERABILITY} for the interoperability sub-IFD.
   */
  function getIfdType() {
    return $this->ifd_type;
  }


  /**
   * Update the IFD type.
   *
   * @param int must be one of the constants defined in {@link
   * PelIfd}: {@link PelIfd::IFD0} for the main image IFD, {@link
   * PelIfd::IFD1} for the thumbnail image IFD, {@link PelIfd::EXIF}
   * for the Exif sub-IFD, {@link PelIfd::GPS} for the GPS sub-IFD, or
   * {@link PelIfd::INTEROPERABILITY} for the interoperability
   * sub-IFD.
   */
  function setIfdType($type) {
    $this->ifd_type = $type;
  }


  /**
   * Return the format of this entry.
   *
   * @return PelFormat the format of this entry.
   */
  function getFormat() {
    return $this->format;
  }


  /**
   * Return the number of components of this entry.
   *
   * @return int the number of components of this entry.
   */
  function getComponents() {
    return $this->components;
  }


  /**
   * Turn this entry into bytes.
   *
   * @param PelByteOrder the desired byte order, which must be either
   * {@link Convert::LITTLE_ENDIAN} or {@link Convert::BIG_ENDIAN}.
   *
   * @return string bytes representing this entry.
   */
  function getBytes($o) {
    return $this->bytes;
  }


  /**
   * Get the value of this entry as text.
   *
   * The value will be returned in a format suitable for presentation,
   * e.g., rationals will be returned as 'x/y', ASCII strings will be
   * returned as themselves etc.
   *
   * @param boolean some values can be returned in a long or more
   * brief form, and this parameter controls that.
   *
   * @return string the value as text.
   */
  abstract function getText($brief = false);


  /**
   * Get the value of this entry.
   *
   * The value returned will generally be the same as the one supplied
   * to the constructor or with {@link setValue()}.  For a formatted
   * version of the value, one should use {@link getText()} instead.
   *
   * @return mixed the unformatted value.
   */
  abstract function getValue();


  /**
   * Set the value of this entry.
   *
   * The value should be in the same format as for the constructor.
   *
   * @param mixed the new value.
   *
   * @abstract
   */
  function setValue($value) {
    /* This (fake) abstract method is here to make it possible for the
     * documentation to refer to PelEntry::setValue().
     *
     * It cannot declared abstract in the proper PHP way, for then PHP
     * wont allow subclasses to define it with two arguments (which is
     * what PelEntryCopyright does).
     */
    throw new PelException('setValue() is abstract.');
  }


  /**
   * Turn this entry into a string.
   *
   * @return string a string representation of this entry.  This is
   * mostly for debugging.
   */
  function __toString() {
    $str = Pel::fmt("  Tag: 0x%04X (%s)\n",
                    $this->tag, PelTag::getName($this->ifd_type, $this->tag));
    $str .= Pel::fmt("    Format    : %d (%s)\n",
                     $this->format, PelFormat::getName($this->format));
    $str .= Pel::fmt("    Components: %d\n", $this->components);
    if ($this->getTag() != PelTag::MAKER_NOTE &&
        $this->getTag() != PelTag::PRINT_IM)
      $str .= Pel::fmt("    Value     : %s\n", print_r($this->getValue(), true));
    $str .= Pel::fmt("    Text      : %s\n", $this->getText());
    return $str;
  }
}

?>
Back to Top