Skip to content

Commit 040e0eb

Browse files
author
Marek Szymczuk
committed
Added checks for "GPSLatitudeRef" and "GPSLongitudeRef".
1 parent 49b5278 commit 040e0eb

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

lib/PHPExif/Mapper/Exiftool.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -162,25 +162,16 @@ public function mapRawData(array $data)
162162
}
163163

164164
// add GPS coordinates, if available
165-
if (count($gpsData) === 2) {
166-
$latitude = $gpsData['lat'];
167-
$longitude = $gpsData['lon'];
168-
169-
if ($latitude !== false && $longitude !== false) {
170-
$gpsLocation = sprintf(
171-
'%s,%s',
172-
(strtoupper($data['GPSLatitudeRef'][0]) === 'S' ? -1 : 1) * $latitude,
173-
(strtoupper($data['GPSLongitudeRef'][0]) === 'W' ? -1 : 1) * $longitude
174-
);
175-
176-
$key = $this->map[self::GPSLATITUDE];
177-
178-
$mappedData[$key] = $gpsLocation;
179-
} else {
180-
unset($mappedData[$this->map[self::GPSLATITUDE]]);
181-
}
165+
if (count($gpsData) === 2 && $gpsData['lat'] !== false && $gpsData['lon'] !== false) {
166+
$gpsLocation = sprintf(
167+
'%s,%s',
168+
(isset($data['GPSLatitudeRef'][0]) && strtoupper($data['GPSLatitudeRef'][0]) === 'S' ? -1 : 1) * $gpsData['lat'],
169+
(isset($data['GPSLongitudeRef'][0]) && strtoupper($data['GPSLongitudeRef'][0]) === 'W' ? -1 : 1) * $gpsData['lon']
170+
);
171+
172+
$mappedData[Exif::GPS] = $gpsLocation;
182173
} else {
183-
unset($mappedData[$this->map[self::GPSLATITUDE]]);
174+
unset($mappedData[Exif::GPS]);
184175
}
185176

186177
return $mappedData;

lib/PHPExif/Mapper/Native.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,17 @@ public function mapRawData(array $data)
179179
$mappedData[$key] = $value;
180180
}
181181

182+
// add GPS coordinates, if available
182183
if (count($gpsData) === 2) {
183184
$gpsLocation = sprintf(
184185
'%s,%s',
185-
(strtoupper($data['GPSLatitudeRef'][0]) === 'S' ? -1 : 1) * $gpsData['lat'],
186-
(strtoupper($data['GPSLongitudeRef'][0]) === 'W' ? -1 : 1) * $gpsData['lon']
186+
(isset($data['GPSLatitudeRef'][0]) && strtoupper($data['GPSLatitudeRef'][0]) === 'S' ? -1 : 1) * $gpsData['lat'],
187+
(isset($data['GPSLongitudeRef'][0]) && strtoupper($data['GPSLongitudeRef'][0]) === 'W' ? -1 : 1) * $gpsData['lon']
187188
);
189+
188190
$mappedData[Exif::GPS] = $gpsLocation;
191+
} else {
192+
unset($mappedData[Exif::GPS]);
189193
}
190194

191195
return $mappedData;

0 commit comments

Comments
 (0)