@@ -204,7 +204,7 @@ public function getExifFromFile($file)
204204 */
205205 public function getIptcData ($ file )
206206 {
207- $ size = getimagesize ($ file , $ info );
207+ getimagesize ($ file , $ info );
208208 $ arrData = array ();
209209 if (isset ($ info ['APP13 ' ])) {
210210 $ iptc = iptcparse ($ info ['APP13 ' ]);
@@ -262,6 +262,18 @@ public function mapData(array $source)
262262 $ exposureTime = '1/ ' . round ($ denominator );
263263 }
264264
265+ $ gpsLocation = false ;
266+ if (isset ($ source ['GPSLatitudeRef ' ]) && isset ($ source ['GPSLongitudeRef ' ])) {
267+ $ latitude = $ this ->extractGPSCoordinate ($ source ['GPSLatitude ' ]);
268+ $ longitude = $ this ->extractGPSCoordinate ($ source ['GPSLongitude ' ]);
269+
270+ $ gpsLocation = sprintf (
271+ '%s,%s ' ,
272+ (strtoupper ($ source ['GPSLatitudeRef ' ][0 ]) === 'S ' ? -1 : 1 ) * $ latitude ,
273+ (strtoupper ($ source ['GPSLongitudeRef ' ][0 ]) === 'W ' ? -1 : 1 ) * $ longitude
274+ );
275+ }
276+
265277 return array (
266278 Exif::APERTURE => (!isset ($ source [self ::SECTION_COMPUTED ]['ApertureFNumber ' ])) ?
267279 false : $ source [self ::SECTION_COMPUTED ]['ApertureFNumber ' ],
@@ -301,6 +313,7 @@ public function mapData(array $source)
301313 Exif::VERTICAL_RESOLUTION => $ vertResolution ,
302314 Exif::WIDTH => (!isset ($ source [self ::SECTION_COMPUTED ]['Width ' ])) ?
303315 false : $ source [self ::SECTION_COMPUTED ]['Width ' ],
316+ Exif::GPS => $ gpsLocation ,
304317 );
305318
306319 $ arrMapping = array (
@@ -345,4 +358,30 @@ public function mapData(array $source)
345358
346359 return $ mappedData ;
347360 }
361+
362+ /**
363+ * Extract GPS coordinates from components array
364+ *
365+ * @param array $components
366+ * @return float
367+ */
368+ protected function extractGPSCoordinate (array $ components )
369+ {
370+ $ components = array_map (array ($ this , 'normalizeGPSComponent ' ), $ components );
371+
372+ return intval ($ components [0 ]) + (intval ($ components [1 ]) / 60 ) + (floatval ($ components [2 ]) / 3600 );
373+ }
374+
375+ /**
376+ * Normalize GPS coordinates components
377+ *
378+ * @param mixed $component
379+ * @return int|float
380+ */
381+ protected function normalizeGPSComponent ($ component )
382+ {
383+ $ parts = explode ('/ ' , $ component );
384+
385+ return count ($ parts ) === 1 ? $ parts [0 ] : (int ) reset ($ parts ) / (int ) end ($ parts );
386+ }
348387}
0 commit comments