@@ -204,7 +204,7 @@ public function getExifFromFile($file)
204
204
*/
205
205
public function getIptcData ($ file )
206
206
{
207
- $ size = getimagesize ($ file , $ info );
207
+ getimagesize ($ file , $ info );
208
208
$ arrData = array ();
209
209
if (isset ($ info ['APP13 ' ])) {
210
210
$ iptc = iptcparse ($ info ['APP13 ' ]);
@@ -262,6 +262,18 @@ public function mapData(array $source)
262
262
$ exposureTime = '1/ ' . round ($ denominator );
263
263
}
264
264
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
+
265
277
return array (
266
278
Exif::APERTURE => (!isset ($ source [self ::SECTION_COMPUTED ]['ApertureFNumber ' ])) ?
267
279
false : $ source [self ::SECTION_COMPUTED ]['ApertureFNumber ' ],
@@ -301,6 +313,7 @@ public function mapData(array $source)
301
313
Exif::VERTICAL_RESOLUTION => $ vertResolution ,
302
314
Exif::WIDTH => (!isset ($ source [self ::SECTION_COMPUTED ]['Width ' ])) ?
303
315
false : $ source [self ::SECTION_COMPUTED ]['Width ' ],
316
+ Exif::GPS => $ gpsLocation ,
304
317
);
305
318
306
319
$ arrMapping = array (
@@ -345,4 +358,30 @@ public function mapData(array $source)
345
358
346
359
return $ mappedData ;
347
360
}
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
+ }
348
387
}
0 commit comments