Changeset 23534 for extensions/exif_view


Ignore:
Timestamp:
Jun 25, 2013, 2:39:29 PM (11 years ago)
Author:
plg
Message:

ability to display GPSLatitude and GPSLongitude (code copied from rv_gmaps plugin)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/exif_view/main.inc.php

    r20066 r23534  
    8282
    8383/**
     84 * GPS function stolen from plugin rv_gmaps
     85 */
     86function ev_parse_fract( $f )
     87{
     88  $nd = explode( '/', $f );
     89  return $nd[0]/$nd[1];
     90}
     91
     92function ev_parse_lat_lon( $arr )
     93{
     94  $v=0;
     95  $v += ev_parse_fract( $arr[0] );
     96  $v += ev_parse_fract( $arr[1] )/60;
     97  $v += ev_parse_fract( $arr[2] )/3600;
     98  return $v;
     99}
     100
     101function ev_exif_to_lat_lon( $exif )
     102{
     103  $exif = array_intersect_key( $exif, array_flip( array('GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude') ) );
     104  if ( count($exif)!=4 )
     105    return '';
     106  if ( !in_array($exif['GPSLatitudeRef'], array('S', 'N') ) )
     107    return 'GPSLatitudeRef not S or N';
     108  if ( !in_array($exif['GPSLongitudeRef'], array('W', 'E') ) )
     109    return 'GPSLongitudeRef not W or E';
     110  if (!is_array($exif['GPSLatitude']) or !is_array($exif['GPSLongitude']) )
     111    return 'GPSLatitude and GPSLongitude are not arrays';
     112 
     113  $lat = ev_parse_lat_lon( $exif['GPSLatitude'] );
     114  if ( $exif['GPSLatitudeRef']=='S' )
     115    $lat = -$lat;
     116  $lon = ev_parse_lat_lon( $exif['GPSLongitude'] );
     117  if ( $exif['GPSLongitudeRef']=='W' )
     118    $lon = -$lon;
     119 
     120  return array ($lat,$lon);
     121}
     122
     123/**
    84124 * EXIF translation.
    85125 *
     
    363403         if (is_array($exif)) {
    364404         loadLang();
     405
     406     // extract latitude/longitude
     407     $latlon = ev_exif_to_lat_lon($exif);
     408     
     409     if (!empty($latlon))
     410     {
     411       $exif['GPSLatitude'] = sprintf('%.6f', $latlon[0]);
     412       $exif['GPSLongitude'] = sprintf('%.6f', $latlon[1]);
     413     }
     414     
    365415           foreach ($exif as $key => $value) {
    366416                         $exif[$key] = exif_key_translation($key, $value);
Note: See TracChangeset for help on using the changeset viewer.