From: Martin Mares Date: Mon, 3 Feb 2014 14:49:20 +0000 (+0100) Subject: Cope with craziness of EXIF geo formats X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=04bf4b29e46d44f6c5d2fee0b8985049d831acbb;p=gallery.git Cope with craziness of EXIF geo formats --- diff --git a/gal/bin/gal-gen b/gal/bin/gal-gen index 0c7921a..dfd434f 100755 --- a/gal/bin/gal-gen +++ b/gal/bin/gal-gen @@ -65,6 +65,22 @@ sub get_meta_basic($$$) { $m->{h} = $h; } +sub parse_geo($) { + my ($g) = @_; + defined $g or return; + if ($g =~ m{^([NEWS]) (\d+)\xb0 ([0-9.]+)'$}) { + $g = $2 + $3/60; + $g = -$g if $1 eq 'W' || $1 eq 'S'; + } elsif ($g =~ m{^([NEWS]) (\d+)\xb0 (\d+)' ([0-9.]+)$}) { + $g = $2 + $3/60 + $4/3600; + $g = -$g if $1 eq 'W' || $1 eq 'S'; + } else { + print "[EXIF: unable to parse coordinate $g] "; + return; + } + return sprintf "%.6f", $g; +} + sub get_meta_exif($$) { my ($f, $m) = @_; $gal->get('CacheExif') or return; @@ -77,29 +93,8 @@ sub get_meta_exif($$) { } # use Data::Dumper; print Dumper($i); - my $lat = $i->{image}->{'Latitude'}; - if ($lat) { - if ($lat =~ m{^([NS]) (\d+)\xb0 ([0-9.]+)'$}) { - $lat = $2 + $3/60; - $lat = -$lat if $1 eq 'S'; - $lat = sprintf "%.6f", $lat; - } else { - print "[EXIF: unable to parse latitude $lat] "; - $lat = undef; - } - } - - my $lon = $i->{image}->{'Longitude'}; - if ($lon) { - if ($lon =~ m{^([WE]) (\d+)\xb0 ([0-9.]+)'$}) { - $lon = $2 + $3/60; - $lon = -$lon if $1 eq 'W'; - $lon = sprintf "%.6f", $lon; - } else { - print "[EXIF: unable to parse longitude $lon] "; - $lon = undef; - } - } + my $lat = parse_geo($i->{image}->{'Latitude'}); + my $lon = parse_geo($i->{image}->{'Longitude'}); my $alt = $i->{image}->{'Altitude'}; if ($alt) {