4 * PEL: PHP Exif Library.
5 * A library with support for reading and
6 * writing all Exif headers in JPEG and TIFF images using PHP.
8 * Copyright (C) 2004, 2005, 2006 Martin Geisler.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program in the file COPYING; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
25 namespace lsolesen\pel;
28 * Classes used to hold longs, both signed and unsigned.
30 * @author Martin Geisler <mgeisler@users.sourceforge.net>
31 * @license http://www.gnu.org/licenses/gpl.html GNU General Public
37 * Class for holding unsigned longs.
39 * This class can hold longs, either just a single long or an array of
40 * longs. The class will be used to manipulate any of the Exif tags
41 * which can have format {@link PelFormat::LONG} like in this
44 * $w = $ifd->getEntry(PelTag::EXIF_IMAGE_WIDTH);
45 * $w->setValue($w->getValue() / 2);
46 * $h = $ifd->getEntry(PelTag::EXIF_IMAGE_HEIGHT);
47 * $h->setValue($h->getValue() / 2);
49 * Here the width and height is updated to 50% of their original
52 * @author Martin Geisler <mgeisler@users.sourceforge.net>
55 class PelEntryLong extends PelEntryNumber
59 * Make a new entry that can hold an unsigned long.
61 * The method accept its arguments in two forms: several integer
62 * arguments or a single array argument. The {@link getValue}
63 * method will always return an array except for when a single
64 * integer argument is given here, or when an array with just a
65 * single integer is given.
67 * This means that one can conveniently use objects like this:
69 * $a = new PelEntryLong(PelTag::EXIF_IMAGE_WIDTH, 123456);
70 * $b = $a->getValue() - 654321;
72 * where the call to {@link getValue} will return an integer instead
73 * of an array with one integer element, which would then have to be
77 * PelTag the tag which this entry represents. This
78 * should be one of the constants defined in {@link PelTag},
79 * e.g., {@link PelTag::IMAGE_WIDTH}, or any other tag which can
80 * have format {@link PelFormat::LONG}.
81 * @param int $value...
82 * the long(s) that this entry will
83 * represent or an array of longs. The argument passed must obey
84 * the same rules as the argument to {@link setValue}, namely that
85 * it should be within range of an unsigned long (32 bit), that is
86 * between 0 and 4294967295 (inclusive). If not, then a {@link
87 * PelExifOverflowException} will be thrown.
89 public function __construct($tag, $value = null)
93 $this->max = 4294967295;
94 $this->format = PelFormat::LONG;
96 $value = func_get_args();
98 $this->setValueArray($value);
102 * Convert a number into bytes.
105 * int the number that should be converted.
107 * PelByteOrder one of {@link PelConvert::LITTLE_ENDIAN} and
108 * {@link PelConvert::BIG_ENDIAN}, specifying the target byte order.
109 * @return string bytes representing the number given.
111 public function numberToBytes($number, $order)
113 return PelConvert::longToBytes($number, $order);