Skip to content

Commit a0de109

Browse files
committed
Merge pull request #19 from wasinger/master
Remove unneeded code in getOrientation, add new test image and fixes for it
2 parents 3790c81 + 4973f38 commit a0de109

File tree

4 files changed

+33
-73
lines changed

4 files changed

+33
-73
lines changed

lib/PHPExif/Exif.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -451,28 +451,6 @@ public function getOrientation()
451451
return false;
452452
}
453453

454-
$value = $this->data[self::ORIENTATION];
455-
456-
// normalize exiftool strings to raw integer values
457-
switch ($value) {
458-
case 'Horizontal (normal)':
459-
return 1;
460-
case 'Mirror horizontal':
461-
return 2;
462-
case 'Rotate 180':
463-
return 3;
464-
case 'Mirror vertical':
465-
return 4;
466-
case 'Mirror horizontal and rotate 270 CW':
467-
return 5;
468-
case 'Rotate 90 CW':
469-
return 6;
470-
case 'Mirror horizontal and rotate 90 CW':
471-
return 7;
472-
case 'Rotate 270 CW':
473-
return 8;
474-
default:
475-
return $value;
476-
}
454+
return $this->data[self::ORIENTATION];
477455
}
478456
}

lib/PHPExif/Reader/Adapter/Native.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,17 @@ public function mapData(array $source)
251251
$vertResolution = (int)reset($resolutionParts);
252252
}
253253

254+
$exposureTime = false;
255+
if (isset($source['ExposureTime'])) {
256+
// normalize ExposureTime
257+
// on one test image, it reported "10/300" instead of "1/30"
258+
list($counter, $denominator) = explode('/', $source['ExposureTime']);
259+
if (intval($counter) !== 1) {
260+
$denominator /= $counter;
261+
}
262+
$exposureTime = '1/' . round($denominator);
263+
}
264+
254265
return array(
255266
Exif::APERTURE => (!isset($source[self::SECTION_COMPUTED]['ApertureFNumber'])) ? false : $source[self::SECTION_COMPUTED]['ApertureFNumber'],
256267
Exif::AUTHOR => (!isset($source['Artist'])) ? false : $source['Artist'],
@@ -260,7 +271,7 @@ public function mapData(array $source)
260271
Exif::COPYRIGHT => (!isset($source[self::SECTION_IPTC]['copyright'])) ? false : $source[self::SECTION_IPTC]['copyright'],
261272
Exif::CREATION_DATE => (!isset($source['DateTimeOriginal'])) ? false : DateTime::createFromFormat('Y:m:d H:i:s', $source['DateTimeOriginal']),
262273
Exif::CREDIT => (!isset($source[self::SECTION_IPTC]['credit'])) ? false : $source[self::SECTION_IPTC]['credit'],
263-
Exif::EXPOSURE => (!isset($source['ExposureTime'])) ? false : $source['ExposureTime'],
274+
Exif::EXPOSURE => $exposureTime,
264275
Exif::FILESIZE => (!isset($source[Exif::FILESIZE]) ? false : $source[Exif::FILESIZE]),
265276
Exif::FOCAL_LENGTH => $focalLength,
266277
Exif::FOCAL_DISTANCE => (!isset($source[self::SECTION_COMPUTED]['FocusDistance'])) ? false : $source[self::SECTION_COMPUTED]['FocusDistance'],
@@ -272,7 +283,7 @@ public function mapData(array $source)
272283
Exif::KEYWORDS => (!isset($source[self::SECTION_IPTC]['keywords'])) ? false : $source[self::SECTION_IPTC]['keywords'],
273284
Exif::MIMETYPE => (!isset($source[Exif::MIMETYPE]) ? false : $source[Exif::MIMETYPE]),
274285
Exif::ORIENTATION => (!isset($source[Exif::ORIENTATION]) ? false : $source[Exif::ORIENTATION]),
275-
Exif::SOFTWARE => (!isset($source['Software'])) ? false : $source['Software'],
286+
Exif::SOFTWARE => (!isset($source['Software'])) ? false : trim($source['Software']),
276287
Exif::SOURCE => (!isset($source[self::SECTION_IPTC]['source'])) ? false : $source[self::SECTION_IPTC]['source'],
277288
Exif::TITLE => (!isset($source[self::SECTION_IPTC]['title'])) ? false : $source[self::SECTION_IPTC]['title'],
278289
Exif::VERTICAL_RESOLUTION => $vertResolution,

tests/PHPExif/ExifTest.php

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -392,40 +392,6 @@ public function testGetOrientation()
392392
$data[\PHPExif\Exif::ORIENTATION] = $expected;
393393
$this->exif->setRawData($data);
394394
$this->assertEquals($expected, $this->exif->getOrientation());
395-
396-
// test normalization of exiftool strings to raw integer values
397-
$expected = 1;
398-
$data[\PHPExif\Exif::ORIENTATION] = 'Horizontal (normal)';
399-
$this->exif->setRawData($data);
400-
$this->assertEquals($expected, $this->exif->getOrientation());
401-
$expected = 2;
402-
$data[\PHPExif\Exif::ORIENTATION] = 'Mirror horizontal';
403-
$this->exif->setRawData($data);
404-
$this->assertEquals($expected, $this->exif->getOrientation());
405-
$expected = 3;
406-
$data[\PHPExif\Exif::ORIENTATION] = 'Rotate 180';
407-
$this->exif->setRawData($data);
408-
$this->assertEquals($expected, $this->exif->getOrientation());
409-
$expected = 4;
410-
$data[\PHPExif\Exif::ORIENTATION] = 'Mirror vertical';
411-
$this->exif->setRawData($data);
412-
$this->assertEquals($expected, $this->exif->getOrientation());
413-
$expected = 5;
414-
$data[\PHPExif\Exif::ORIENTATION] = 'Mirror horizontal and rotate 270 CW';
415-
$this->exif->setRawData($data);
416-
$this->assertEquals($expected, $this->exif->getOrientation());
417-
$expected = 6;
418-
$data[\PHPExif\Exif::ORIENTATION] = 'Rotate 90 CW';
419-
$this->exif->setRawData($data);
420-
$this->assertEquals($expected, $this->exif->getOrientation());
421-
$expected = 7;
422-
$data[\PHPExif\Exif::ORIENTATION] = 'Mirror horizontal and rotate 90 CW';
423-
$this->exif->setRawData($data);
424-
$this->assertEquals($expected, $this->exif->getOrientation());
425-
$expected = 8;
426-
$data[\PHPExif\Exif::ORIENTATION] = 'Rotate 270 CW';
427-
$this->exif->setRawData($data);
428-
$this->assertEquals($expected, $this->exif->getOrientation());
429395
}
430396

431397
/**
@@ -435,25 +401,30 @@ public function testAdapterConsistency()
435401
{
436402
$reflClass = new \ReflectionClass('\PHPExif\Exif');
437403
$methods = $reflClass->getMethods(ReflectionMethod::IS_PUBLIC);
438-
$file = PHPEXIF_TEST_ROOT . '/files/morning_glory_pool_500.jpg';
404+
$testfiles = array(
405+
PHPEXIF_TEST_ROOT . '/files/morning_glory_pool_500.jpg',
406+
PHPEXIF_TEST_ROOT . '/files/dsc_5794.jpg'
407+
);
439408

440409
$adapter_exiftool = new \PHPExif\Reader\Adapter\Exiftool();
441410
$adapter_native = new \PHPExif\Reader\Adapter\Native();
442411

443-
$result_exiftool = $adapter_exiftool->getExifFromFile($file);
444-
$result_native = $adapter_native->getExifFromFile($file);
445-
446-
// find all Getter methods on the results and compare its output
447-
foreach ($methods as $method) {
448-
$name = $method->getName();
449-
if (strpos($name, 'get') !== 0 || $name == 'getRawData') {
450-
continue;
412+
foreach ($testfiles as $file) {
413+
$result_exiftool = $adapter_exiftool->getExifFromFile($file);
414+
$result_native = $adapter_native->getExifFromFile($file);
415+
416+
// find all Getter methods on the results and compare its output
417+
foreach ($methods as $method) {
418+
$name = $method->getName();
419+
if (strpos($name, 'get') !== 0 || $name == 'getRawData') {
420+
continue;
421+
}
422+
$this->assertEquals(
423+
call_user_func(array($result_native, $name)),
424+
call_user_func(array($result_exiftool, $name)),
425+
'Adapter difference detected in method "' . $name . '" on image "' . basename($file) . '"'
426+
);
451427
}
452-
$this->assertEquals(
453-
call_user_func(array($result_native, $name)),
454-
call_user_func(array($result_exiftool, $name)),
455-
'Adapter difference in method ' . $name
456-
);
457428
}
458429
}
459430
}

tests/files/dsc_5794.jpg

225 KB
Loading

0 commit comments

Comments
 (0)