Skip to content

Instantly share code, notes, and snippets.

@ephphatha
Last active August 29, 2015 14:02
Show Gist options
  • Save ephphatha/e637153e6fdf16f787bb to your computer and use it in GitHub Desktop.
Save ephphatha/e637153e6fdf16f787bb to your computer and use it in GitHub Desktop.
A script used to pull location information from .png files. Absolutely no error handling, needs imagemagick installed.
$images = Get-ChildItem -Name | Where-Object { $_ -match ".png$" }
if ($images) {
foreach ($image in $images) {
$gpstags = identify -format "%[EXIF:GPSL*]" $image
$latitude = 1
$longitude = 1
foreach ($tag in $gpstags) {
$tokens = $tag.split('=')
$tokens[0] = $tokens[0].trimStart("exif:")
if (!$tokens[0].endsWith("Ref")) {
$dms = $tokens[1].replace(' ', '').split(',')
$degree_parts = $dms[0].split('/')
$minute_parts = $dms[1].split('/')
$second_parts = $dms[2].split('/')
$decimal_degrees = $degree_parts[0] / $degree_parts[1] + ( $minute_parts[0] / $minute_parts[1] + ( $second_parts[0] / $second_parts[1] ) / 60 ) / 60
if ($tokens[0] -eq "GPSLatitude") {
$latitude *= $decimal_degrees
} else {
$longitude *= $decimal_degrees
}
} else {
if ($tokens[0].startsWith("GPSLatitude") -and $tokens[1] -eq "S") {
$latitude = -$latitude
} elseif ($tokens[1] -eq "W") {
$longitude = -$longitude
}
}
}
echo "$latitude, $longitude"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment