4 * PEL: PHP Exif Library. A library with support for reading and
5 * writing all Exif headers in JPEG and TIFF images using PHP.
7 * Copyright (C) 2005, 2006 Martin Geisler.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program in the file COPYING; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22 * Boston, MA 02110-1301 USA
26 use lsolesen\pel\PelJpeg;
28 class NikonE5000Test extends \PHPUnit_Framework_TestCase
30 public function testRead()
32 Pel::clearExceptions();
33 Pel::setStrictParsing(false);
34 $jpeg = new PelJpeg(dirname(__FILE__) . '/nikon-e5000.jpg');
36 $exif = $jpeg->getExif();
37 $this->assertInstanceOf('lsolesen\pel\PelExif', $exif);
39 $tiff = $exif->getTiff();
40 $this->assertInstanceOf('lsolesen\pel\PelTiff', $tiff);
43 $ifd0 = $tiff->getIfd();
44 $this->assertInstanceOf('lsolesen\pel\PelIfd', $ifd0);
46 /* Start of IDF $ifd0. */
47 $this->assertEquals(count($ifd0->getEntries()), 9);
49 $entry = $ifd0->getEntry(270); // ImageDescription
50 $this->assertInstanceOf('lsolesen\pel\PelEntryAscii', $entry);
51 $this->assertEquals($entry->getValue(), ' ');
52 $this->assertEquals($entry->getText(), ' ');
54 $entry = $ifd0->getEntry(271); // Make
55 $this->assertInstanceOf('lsolesen\pel\PelEntryAscii', $entry);
56 $this->assertEquals($entry->getValue(), 'NIKON');
57 $this->assertEquals($entry->getText(), 'NIKON');
59 $entry = $ifd0->getEntry(272); // Model
60 $this->assertInstanceOf('lsolesen\pel\PelEntryAscii', $entry);
61 $this->assertEquals($entry->getValue(), 'E5000');
62 $this->assertEquals($entry->getText(), 'E5000');
64 $entry = $ifd0->getEntry(282); // XResolution
65 $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
66 $this->assertEquals($entry->getValue(), array(
70 $this->assertEquals($entry->getText(), '300/1');
72 $entry = $ifd0->getEntry(283); // YResolution
73 $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
74 $this->assertEquals($entry->getValue(), array(
78 $this->assertEquals($entry->getText(), '300/1');
80 $entry = $ifd0->getEntry(296); // ResolutionUnit
81 $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
82 $this->assertEquals($entry->getValue(), 2);
83 $this->assertEquals($entry->getText(), 'Inch');
85 $entry = $ifd0->getEntry(305); // Software
86 $this->assertInstanceOf('lsolesen\pel\PelEntryAscii', $entry);
87 $this->assertEquals($entry->getValue(), 'E5000v1.6');
88 $this->assertEquals($entry->getText(), 'E5000v1.6');
90 $entry = $ifd0->getEntry(306); // DateTime
91 $this->assertInstanceOf('lsolesen\pel\PelEntryTime', $entry);
92 $this->assertEquals($entry->getValue(), 1021992832);
93 $this->assertEquals($entry->getText(), '2002:05:21 14:53:52');
95 $entry = $ifd0->getEntry(531); // YCbCrPositioning
96 $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
97 $this->assertEquals($entry->getValue(), 1);
98 $this->assertEquals($entry->getText(), 'centered');
100 /* Sub IFDs of $ifd0. */
101 $this->assertEquals(count($ifd0->getSubIfds()), 2);
102 $ifd0_0 = $ifd0->getSubIfd(2); // IFD Exif
103 $this->assertInstanceOf('lsolesen\pel\PelIfd', $ifd0_0);
105 /* Start of IDF $ifd0_0. */
106 $this->assertEquals(count($ifd0_0->getEntries()), 22);
108 $entry = $ifd0_0->getEntry(33434); // ExposureTime
109 $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
110 $this->assertEquals($entry->getValue(), array(
114 $this->assertEquals($entry->getText(), '1/60 sec.');
116 $entry = $ifd0_0->getEntry(33437); // FNumber
117 $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
118 $this->assertEquals($entry->getValue(), array(
122 $this->assertEquals($entry->getText(), 'f/2.8');
124 $entry = $ifd0_0->getEntry(34850); // ExposureProgram
125 $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
126 $this->assertEquals($entry->getValue(), 2);
127 $this->assertEquals($entry->getText(), 'Normal program');
129 $entry = $ifd0_0->getEntry(34855); // ISOSpeedRatings
130 $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
131 $this->assertEquals($entry->getValue(), 100);
132 $this->assertEquals($entry->getText(), '100');
134 $entry = $ifd0_0->getEntry(36864); // ExifVersion
135 $this->assertInstanceOf('lsolesen\pel\PelEntryVersion', $entry);
136 $this->assertEquals($entry->getValue(), 2.1);
137 $this->assertEquals($entry->getText(), 'Exif Version 2.1');
139 $entry = $ifd0_0->getEntry(36867); // DateTimeOriginal
140 $this->assertInstanceOf('lsolesen\pel\PelEntryTime', $entry);
141 $this->assertEquals($entry->getValue(), 1021992832);
142 $this->assertEquals($entry->getText(), '2002:05:21 14:53:52');
144 $entry = $ifd0_0->getEntry(36868); // DateTimeDigitized
145 $this->assertInstanceOf('lsolesen\pel\PelEntryTime', $entry);
146 $this->assertEquals($entry->getValue(), 1021992832);
147 $this->assertEquals($entry->getText(), '2002:05:21 14:53:52');
149 $entry = $ifd0_0->getEntry(37121); // ComponentsConfiguration
150 $this->assertInstanceOf('lsolesen\pel\PelEntryUndefined', $entry);
151 $this->assertEquals($entry->getValue(), "\x01\x02\x03\0");
152 $this->assertEquals($entry->getText(), 'Y Cb Cr -');
154 $entry = $ifd0_0->getEntry(37380); // ExposureBiasValue
155 $this->assertInstanceOf('lsolesen\pel\PelEntrySRational', $entry);
156 $this->assertEquals($entry->getValue(), array(
160 $this->assertEquals($entry->getText(), '0.0');
162 $entry = $ifd0_0->getEntry(37381); // MaxApertureValue
163 $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
164 $this->assertEquals($entry->getValue(), array(
168 $this->assertEquals($entry->getText(), '3/1');
170 $entry = $ifd0_0->getEntry(37383); // MeteringMode
171 $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
172 $this->assertEquals($entry->getValue(), 5);
173 $this->assertEquals($entry->getText(), 'Pattern');
175 $entry = $ifd0_0->getEntry(37384); // LightSource
176 $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
177 $this->assertEquals($entry->getValue(), 0);
178 $this->assertEquals($entry->getText(), 'Unknown');
180 $entry = $ifd0_0->getEntry(37385); // Flash
181 $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
182 $this->assertEquals($entry->getValue(), 0);
183 $this->assertEquals($entry->getText(), 'Flash did not fire.');
185 $entry = $ifd0_0->getEntry(37386); // FocalLength
186 $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
187 $this->assertEquals($entry->getValue(), array(
191 $this->assertEquals($entry->getText(), '7.1 mm');
193 $entry = $ifd0_0->getEntry(37500); // MakerNote
194 $this->assertInstanceOf('lsolesen\pel\PelEntryUndefined', $entry);
195 $expected = "\x15\0\x01\0\x07\0\x04\0\0\0\0\x01\0\0\x02\0\x03\0\x02\0\0\0\0\0\0\0\x03\0\x02\0\x06\0\0\0\xbc\x03\0\0\x04\0\x02\0\x08\0\0\0\xc2\x03\0\0\x05\0\x02\0\x0d\0\0\0\xca\x03\0\0\x06\0\x02\0\x07\0\0\0\xd8\x03\0\0\x07\0\x02\0\x07\0\0\0\xe0\x03\0\0\x08\0\x02\0\x0d\0\0\0\xe8\x03\0\0\x0a\0\x05\0\x01\0\0\0\xf6\x03\0\0\x0f\0\x02\0\x07\0\0\0\xfe\x03\0\0\x11\0\x04\0\x01\0\0\0\x14\x05\0\0\x80\0\x02\0\x0e\0\0\0\x06\x04\0\0\x82\0\x02\0\x0d\0\0\0\x14\x04\0\0\x85\0\x05\0\x01\0\0\0\x22\x04\0\0\x86\0\x05\0\x01\0\0\0\x2a\x04\0\0\x88\0\x07\0\x04\0\0\0\0\0\0\0\x8f\0\x02\0\x11\0\0\0\x32\x04\0\0\x94\0\x08\0\x01\0\0\0\0\0\0\0\x95\0\x02\0\x05\0\0\0\x44\x04\0\0\0\x0e\x07\0\xca\0\0\0\x4a\x04\0\0\x10\x0e\x04\0\x01\0\0\0\x72\x05\0\0\0\0\0\0\x43\x4f\x4c\x4f\x52\0\x46\x49\x4e\x45\x20\x20\x20\0\x41\x55\x54\x4f\x20\x20\x20\x20\x20\x20\x20\x20\0\x31\x41\x55\x54\x4f\x20\x20\0\0\x41\x46\x2d\x43\x20\x20\0\x3a\x4e\x4f\x52\x4d\x41\x4c\x20\x20\x20\x20\x20\x20\0\0\x80\x22\0\0\xe8\x03\0\0\x41\x55\x54\x4f\x20\x20\0\0\x41\x55\x54\x4f\x20\x20\x20\x20\x20\x20\x20\x20\x20\0\x4f\x46\x46\x20\x20\x20\x20\x20\x20\x20\x20\x20\0\x20\0\0\0\0\0\0\0\0\x01\0\0\0\x01\0\0\0\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\0\x20\x4f\x46\x46\x20\0\x20\x50\x72\x69\x6e\x74\x49\x4d\0\x30\x31\x30\x30\0\0\x0d\0\x01\0\x16\0\x16\0\x02\0\x01\0\0\0\x03\0\x5e\0\0\0\x07\0\0\0\0\0\x08\0\0\0\0\0\x09\0\0\0\0\0\x0a\0\0\0\0\0\x0b\0\xa6\0\0\0\x0c\0\0\0\0\0\x0d\0\0\0\0\0\x0e\0\xbe\0\0\0\0\x01\x05\0\0\0\x01\x01\x01\0\0\0\x09\x11\0\0\x10\x27\0\0\x0b\x0f\0\0\x10\x27\0\0\x97\x05\0\0\x10\x27\0\0\xb0\x08\0\0\x10\x27\0\0\x01\x1c\0\0\x10\x27\0\0\x5e\x02\0\0\x10\x27\0\0\x8b\0\0\0\x10\x27\0\0\xcb\x03\0\0\x10\x27\0\0\xe5\x1b\0\0\x10\x27\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x06\0";
196 $this->assertEquals($entry->getValue(), $expected);
197 $this->assertEquals($entry->getText(), '604 bytes unknown MakerNote data');
199 $entry = $ifd0_0->getEntry(37510); // UserComment
200 $this->assertInstanceOf('lsolesen\pel\PelEntryUserComment', $entry);
201 $this->assertEquals($entry->getValue(), ' ');
202 $this->assertEquals($entry->getText(), ' ');
204 $entry = $ifd0_0->getEntry(40960); // FlashPixVersion
205 $this->assertInstanceOf('lsolesen\pel\PelEntryVersion', $entry);
206 $this->assertEquals($entry->getValue(), 1);
207 $this->assertEquals($entry->getText(), 'FlashPix Version 1.0');
209 $entry = $ifd0_0->getEntry(40961); // ColorSpace
210 $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
211 $this->assertEquals($entry->getValue(), 1);
212 $this->assertEquals($entry->getText(), 'sRGB');
214 $entry = $ifd0_0->getEntry(40962); // PixelXDimension
215 $this->assertInstanceOf('lsolesen\pel\PelEntryLong', $entry);
216 $this->assertEquals($entry->getValue(), 1600);
217 $this->assertEquals($entry->getText(), '1600');
219 $entry = $ifd0_0->getEntry(40963); // PixelYDimension
220 $this->assertInstanceOf('lsolesen\pel\PelEntryLong', $entry);
221 $this->assertEquals($entry->getValue(), 1200);
222 $this->assertEquals($entry->getText(), '1200');
224 $entry = $ifd0_0->getEntry(41728); // FileSource
225 $this->assertInstanceOf('lsolesen\pel\PelEntryUndefined', $entry);
226 $this->assertEquals($entry->getValue(), "\x03");
227 $this->assertEquals($entry->getText(), 'DSC');
229 $entry = $ifd0_0->getEntry(41729); // SceneType
230 $this->assertInstanceOf('lsolesen\pel\PelEntryUndefined', $entry);
231 $this->assertEquals($entry->getValue(), "\x01");
232 $this->assertEquals($entry->getText(), 'Directly photographed');
234 /* Sub IFDs of $ifd0_0. */
235 $this->assertEquals(count($ifd0_0->getSubIfds()), 0);
237 $this->assertEquals($ifd0_0->getThumbnailData(), '');
240 $ifd0_1 = $ifd0_0->getNextIfd();
241 $this->assertNull($ifd0_1);
242 /* End of IFD $ifd0_0. */
243 $ifd0_1 = $ifd0->getSubIfd(3); // IFD GPS
244 $this->assertInstanceOf('lsolesen\pel\PelIfd', $ifd0_1);
246 /* Start of IDF $ifd0_1. */
247 $this->assertEquals(count($ifd0_1->getEntries()), 0);
249 /* Sub IFDs of $ifd0_1. */
250 $this->assertEquals(count($ifd0_1->getSubIfds()), 0);
252 $this->assertEquals($ifd0_1->getThumbnailData(), '');
255 $ifd0_2 = $ifd0_1->getNextIfd();
256 $this->assertNull($ifd0_2);
257 /* End of IFD $ifd0_1. */
259 $this->assertEquals($ifd0->getThumbnailData(), '');
262 $ifd1 = $ifd0->getNextIfd();
263 $this->assertInstanceOf('lsolesen\pel\PelIfd', $ifd1);
264 /* End of IFD $ifd0. */
266 /* Start of IDF $ifd1. */
267 $this->assertEquals(count($ifd1->getEntries()), 4);
269 $entry = $ifd1->getEntry(259); // Compression
270 $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
271 $this->assertEquals($entry->getValue(), 6);
272 $this->assertEquals($entry->getText(), 'JPEG compression');
274 $entry = $ifd1->getEntry(282); // XResolution
275 $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
276 $this->assertEquals($entry->getValue(), array(
280 $this->assertEquals($entry->getText(), '72/1');
282 $entry = $ifd1->getEntry(283); // YResolution
283 $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
284 $this->assertEquals($entry->getValue(), array(
288 $this->assertEquals($entry->getText(), '72/1');
290 $entry = $ifd1->getEntry(296); // ResolutionUnit
291 $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
292 $this->assertEquals($entry->getValue(), 2);
293 $this->assertEquals($entry->getText(), 'Inch');
295 /* Sub IFDs of $ifd1. */
296 $this->assertEquals(count($ifd1->getSubIfds()), 0);
298 $thumb_data = file_get_contents(dirname(__FILE__) . '/nikon-e5000-thumb.jpg');
299 $this->assertEquals($ifd1->getThumbnailData(), $thumb_data);
302 $ifd2 = $ifd1->getNextIfd();
303 $this->assertNull($ifd2);
304 /* End of IFD $ifd1. */
306 $exceptions = Pel::getExceptions();
307 $this->assertInstanceOf('lsolesen\pel\PelException', $exceptions[0]);
308 $this->assertEquals($exceptions[0]->getMessage(), 'Found trailing content after EOI: 1396 bytes');