diff --git a/lib/PHPExif/Mapper/Exiftool.php b/lib/PHPExif/Mapper/Exiftool.php index 70fb732..a5d1ac8 100644 --- a/lib/PHPExif/Mapper/Exiftool.php +++ b/lib/PHPExif/Mapper/Exiftool.php @@ -286,12 +286,13 @@ public function mapRawData(array $data) : array } break; case self::GPSLATITUDE: - $latitudeRef = !array_key_exists('GPS:GPSLatitudeRef', $data) ? - 'N' : $data['GPS:GPSLatitudeRef'][0]; $value = $this->extractGPSCoordinates($value); if ($value === false) { continue 2; } + $latitudeRef = !array_key_exists('GPS:GPSLatitudeRef', $data) + || $data['GPS:GPSLatitudeRef'] === null || $data['GPS:GPSLatitudeRef'] === '' ? + 'N' : $data['GPS:GPSLatitudeRef'][0]; $value *= strtoupper($latitudeRef) === 'S' ? -1 : 1; break; case self::GPSLONGITUDE_QUICKTIME: @@ -301,12 +302,13 @@ public function mapRawData(array $data) : array } break; case self::GPSLONGITUDE: - $longitudeRef = !array_key_exists('GPS:GPSLongitudeRef', $data) ? - 'E' : $data['GPS:GPSLongitudeRef'][0]; $value = $this->extractGPSCoordinates($value); if ($value === false) { continue 2; } + $longitudeRef = !array_key_exists('GPS:GPSLongitudeRef', $data) + || $data['GPS:GPSLongitudeRef'] === null || $data['GPS:GPSLongitudeRef'] === '' ? + 'E' : $data['GPS:GPSLongitudeRef'][0]; $value *= strtoupper($longitudeRef) === 'W' ? -1 : 1; break; case self::GPSALTITUDE: diff --git a/lib/PHPExif/Mapper/ImageMagick.php b/lib/PHPExif/Mapper/ImageMagick.php index 109ff0f..079a685 100644 --- a/lib/PHPExif/Mapper/ImageMagick.php +++ b/lib/PHPExif/Mapper/ImageMagick.php @@ -184,21 +184,23 @@ public function mapRawData(array $data) : array $value = preg_split('/([\s,]+)/', $value)[0]; break; case self::GPSLATITUDE: - $latitudeRef = !array_key_exists('exif:GPSLatitudeRef', $data) ? - 'N' : $data['exif:GPSLatitudeRef'][0]; $value = $this->extractGPSCoordinates($value); if ($value === false) { continue 2; } + $latitudeRef = !array_key_exists('exif:GPSLatitudeRef', $data) + || $data['exif:GPSLatitudeRef'] === null || $data['exif:GPSLatitudeRef'] === '' ? + 'N' : $data['exif:GPSLatitudeRef'][0]; $value *= strtoupper($latitudeRef) === 'S' ? -1 : 1; break; case self::GPSLONGITUDE: - $longitudeRef = !array_key_exists('exif:GPSLongitudeRef', $data) ? - 'E' : $data['exif:GPSLongitudeRef'][0]; $value = $this->extractGPSCoordinates($value); if ($value === false) { continue 2; } + $longitudeRef = !array_key_exists('exif:GPSLongitudeRef', $data) + || $data['exif:GPSLongitudeRef'] === null || $data['exif:GPSLongitudeRef'] === '' ? + 'E' : $data['exif:GPSLongitudeRef'][0]; $value *= strtoupper($longitudeRef) === 'W' ? -1 : 1; break; case self::GPSALTITUDE: diff --git a/lib/PHPExif/Mapper/Native.php b/lib/PHPExif/Mapper/Native.php index 02b52e4..9d328a1 100644 --- a/lib/PHPExif/Mapper/Native.php +++ b/lib/PHPExif/Mapper/Native.php @@ -235,8 +235,9 @@ public function mapRawData(array $data) : array $value = (int) reset($resolutionParts); break; case self::GPSLATITUDE: - $GPSLatitudeRef = ''; - if (array_key_exists('GPSLatitudeRef', $data) && $data['GPSLatitudeRef'][0] !== '') { + $GPSLatitudeRef = 'N'; + if (array_key_exists('GPSLatitudeRef', $data) + && $data['GPSLatitudeRef'] !== null && $data['GPSLatitudeRef'][0] !== '') { $GPSLatitudeRef = $data['GPSLatitudeRef'][0]; } $value = $this->extractGPSCoordinate((array)$value, $GPSLatitudeRef); @@ -245,8 +246,9 @@ public function mapRawData(array $data) : array } break; case self::GPSLONGITUDE: - $GPSLongitudeRef = ''; - if (array_key_exists('GPSLongitudeRef', $data) && $data['GPSLongitudeRef'][0] !== '') { + $GPSLongitudeRef = 'E'; + if (array_key_exists('GPSLongitudeRef', $data) + && $data['GPSLongitudeRef'] !== null && $data['GPSLongitudeRef'][0] !== '') { $GPSLongitudeRef = $data['GPSLongitudeRef'][0]; } $value = $this->extractGPSCoordinate((array)$value, $GPSLongitudeRef); @@ -255,6 +257,10 @@ public function mapRawData(array $data) : array } break; case self::GPSALTITUDE: + $value = $this->normalizeComponent($value); + if ($value === false) { + continue 2; + } $flp = 1; if (array_key_exists('GPSAltitudeRef', $data) && $data['GPSAltitudeRef'][0] !== '') { $flp = ( @@ -262,10 +268,6 @@ public function mapRawData(array $data) : array || $data['GPSAltitudeRef'][0] === "\u{0001}" ) ? -1 : 1; } - $value = $this->normalizeComponent($value); - if ($value === false) { - continue 2; - } $value *= $flp; break; case self::IMGDIRECTION: diff --git a/tests/PHPExif/Mapper/ExiftoolMapperTest.php b/tests/PHPExif/Mapper/ExiftoolMapperTest.php index 898cc28..1abeb05 100644 --- a/tests/PHPExif/Mapper/ExiftoolMapperTest.php +++ b/tests/PHPExif/Mapper/ExiftoolMapperTest.php @@ -400,6 +400,24 @@ public function testMapRawDataOnlyLatitude() $this->assertCount(1, $result); } + /** + * @group mapper + * @covers \PHPExif\Mapper\Exiftool::mapRawData + */ + public function testMapRawDataCorrectlyIgnoresEmptyGPSData() + { + $result = $this->mapper->mapRawData( + array( + \PHPExif\Mapper\Exiftool::GPSLATITUDE => '', + 'GPS:GPSLatitudeRef' => '', + \PHPExif\Mapper\Exiftool::GPSLONGITUDE => '', + 'GPS:GPSLongitudeRef' => '', + ) + ); + + $this->assertEquals(false, reset($result)); + } + /** * @group mapper * @covers \PHPExif\Mapper\Exiftool::mapRawData @@ -512,6 +530,21 @@ public function testMapRawDataCorrectlyNegativeAltitude() $this->assertEquals($expected, reset($result)); } + /** + * @group mapper + * @covers \PHPExif\Mapper\Exiftool::mapRawData + */ + public function testMapRawDataCorrectlyIgnoresIncorrectAltitude() + { + $result = $this->mapper->mapRawData( + array( + \PHPExif\Mapper\Exiftool::GPSALTITUDE => 'undef', + 'GPS:GPSAltitudeRef' => '0', + ) + ); + $this->assertEquals(false, reset($result)); + } + /** * @group mapper * @covers \PHPExif\Mapper\Exiftool::mapRawData diff --git a/tests/PHPExif/Mapper/ImageMagickMapperTest.php b/tests/PHPExif/Mapper/ImageMagickMapperTest.php index ce60598..9d1184f 100644 --- a/tests/PHPExif/Mapper/ImageMagickMapperTest.php +++ b/tests/PHPExif/Mapper/ImageMagickMapperTest.php @@ -361,9 +361,9 @@ public function testMapRawDataIncorrectlyFormatedGPSData() $result = $this->mapper->mapRawData( array( \PHPExif\Mapper\ImageMagick::GPSLATITUDE => '40/1 20/1 42857/100000', - 'GPS:GPSLatitudeRef' => 'N', + 'exif:GPSLatitudeRef' => 'N', \PHPExif\Mapper\ImageMagick::GPSLONGITUDE => '20/1 10/1 233333/100000', - 'GPS:GPSLongitudeRef' => 'W', + 'exif:GPSLongitudeRef' => 'W', ) ); $this->assertCount(0, $result); @@ -402,13 +402,31 @@ public function testMapRawDataOnlyLatitude() $result = $this->mapper->mapRawData( array( \PHPExif\Mapper\ImageMagick::GPSLATITUDE => '40.333452381', - 'GPS:GPSLatitudeRef' => 'North', + 'exif:GPSLatitudeRef' => 'North', ) ); $this->assertCount(1, $result); } + /** + * @group mapper + * @covers \PHPExif\Mapper\ImageMagick::mapRawData + */ + public function testMapRawDataCorrectlyIgnoresEmptyGPSData() + { + $result = $this->mapper->mapRawData( + array( + \PHPExif\Mapper\ImageMagick::GPSLATITUDE => '0/0, 0/0, 0/0', + 'exif:GPSLatitudeRef' => '', + \PHPExif\Mapper\ImageMagick::GPSLONGITUDE => '0/0, 0/0, 0/0', + 'exif:GPSLongitudeRef' => '', + ) + ); + + $this->assertEquals(false, reset($result)); + } + public function testMapRawDataCorrectlyFormatsDifferentDateTimeString() { @@ -477,6 +495,21 @@ public function testMapRawDataCorrectlyNegativeAltitude() $this->assertEquals($expected, reset($result)); } + /** + * @group mapper + * @covers \PHPExif\Mapper\ImageMagick::mapRawData + */ + public function testMapRawDataCorrectlyIgnoresIncorrectAltitude() + { + $result = $this->mapper->mapRawData( + array( + \PHPExif\Mapper\ImageMagick::GPSALTITUDE => '0/0', + 'exif:GPSAltitudeRef' => '0', + ) + ); + $this->assertEquals(false, reset($result)); + } + /** * @group mapper diff --git a/tests/PHPExif/Mapper/NativeMapperTest.php b/tests/PHPExif/Mapper/NativeMapperTest.php index 2285c5a..a637319 100644 --- a/tests/PHPExif/Mapper/NativeMapperTest.php +++ b/tests/PHPExif/Mapper/NativeMapperTest.php @@ -345,6 +345,24 @@ public function testMapRawDataCorrectlyFormatsGPSData() } } + /** + * @group mapper + * @covers \PHPExif\Mapper\Native::mapRawData + */ + public function testMapRawDataCorrectlyIgnoresEmptyGPSData() + { + $result = $this->mapper->mapRawData( + array( + 'GPSLatitude' => array('0/0', '0/0', '0/0'), + 'GPSLatitudeRef' => null, + 'GPSLongitude' => array('0/0', '0/0', '0/0'), + 'GPSLongitudeRef' => null, + ) + ); + + $this->assertEquals(false, reset($result)); + } + /** * @group mapper * @covers \PHPExif\Mapper\Native::mapRawData @@ -368,6 +386,21 @@ public function testMapRawDataCorrectlyFormatsAltitudeData() } } + /** + * @group mapper + * @covers \PHPExif\Mapper\Native::mapRawData + */ + public function testMapRawDataCorrectlyIgnoresIncorrectAltitude() + { + $result = $this->mapper->mapRawData( + array( + 'GPSAltitude' => "0/0", + 'GPSAltitudeRef' => chr(0), + ) + ); + $this->assertEquals(false, reset($result)); + } + public function testMapRawDataCorrectlyFormatsDifferentDateTimeString() { $rawData = array(