Created
April 12, 2012 06:28
-
-
Save JasonMillward/2365115 to your computer and use it in GitHub Desktop.
Perl - Latlong
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
### THINGS THAT GO AT THE TOP. NOTHING IMPORTANT | |
use Image::ExifTool qw(:Public); | |
use warnings; | |
use strict; | |
sub ConvertLatLong | |
{ | |
my $var = shift(@_); | |
my ($deg , $min, $sec); | |
$var =~ s/[^0-9\ \.]//g; | |
my @a = split(/ +/, $var); | |
if (scalar(@a) eq 3) { | |
($deg, $min, $sec) = @a; | |
$var = $deg + $min/60 + $sec/3600; | |
} elsif (scalar(@a) eq 2) { | |
($deg, $min) = @a; | |
$var = $deg + $min/60; | |
} else { | |
$var = ""; | |
} | |
return $var; | |
} | |
my $image_info = ImageInfo( "/path/to/jpg.jpg", ['exif:*'] ); | |
my $long = $image_info->{'GPSLongitude (1)'} | |
if exists $image_info->{'GPSLongitude (1)'}; | |
my $lat = $image_info->{'GPSLatitude (1)'} | |
if exists $image_info->{'GPSLatitude (1)'}; | |
if ( defined($long) && defined($lat) ) { | |
if ( ( $long ne "" ) && ( $lat ne "" ) ) { | |
$lat = abs( ConvertLatLong($lat) ) * -1; | |
$long = ConvertLatLong($long); | |
print "GPS Data has been found."; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment