Created
January 23, 2017 14:11
-
-
Save rkachowski/6b49d67bb651300cdfb13609fd84a77a to your computer and use it in GitHub Desktop.
create google map links from exif data in jpg files
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/env ruby | |
def run | |
dir = ARGV[0] || Dir.pwd | |
Dir[File.join(dir,'*.jpg')].each do |file| | |
gps = gps_for_file file | |
if gps | |
puts "#### #{File.basename file} -> http://www.google.com/maps/place/#{gps[0]},-#{gps[1]}" | |
end | |
end | |
end | |
def gps_for_file file | |
gps = `identify -format "%[EXIF:*]" #{file} 2>/dev/null | grep GPS `.split("\n").select{|g| g=~ /(:?Latitude|Longitude)\b/} | |
return if gps.empty? | |
long = gps.find{|f| f=~ /Longitude/ } | |
lat = gps.find{|f| f=~ /Latitude/ } | |
get_dms = ->(str){ str.scan(/(\d+)\/(\d+)/).map{|c| c.flatten.each_slice(2).map{|n,d| n.to_f / d.to_f}} } | |
coords = [get_dms.call(lat).flatten, get_dms.call(long).flatten] | |
coords.map {|c| c[0] + c[1] / 60.0 + c[2] / 3600.0 } | |
end | |
run if $0 == __FILE__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment