Instantly share code, notes, and snippets.

Last active September 20, 2017 03:39
Image EXIF Distance Tools

# Image EXIF Distance Tools

Some scripts for finding the distance between the location of an image and the Bank of America Building in Atlanta (or maybe you have a better use-case).

## Usage

``````\$ ./image-distance.sh <filename.jpg>
``````

Example:

``````./image-distance.sh images/IMG_20170913_083501.jpg
Filename: images/IMG_20170913_083501.jpg
Latitude: 33.7660111111
Longitude: -84.3974111111
Distance to BofA Building: 0.948619993884 km
``````

Under the hood, this makes calls to `exif-gps.sh`, which grabs some specific Exif metadata info from an image, using `exiftool`, formats the results, and uses them to call `distance.py`, which parses out the lat/lon strings and calculates the distance to the BofA building.

## Why?

... because that goal will serve to organize and measure the best of our energies and skills, because that challenge is one that we are willing to accept, one we are unwilling to postpone, and one we intend to win

This file contains 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 python import sys import LatLon LATLON_BOFA = LatLon.LatLon(33.7706862, -84.3888361) def get_exif_latlon(lat, lon): """ Where lat/lon are strings like: - "33 deg 45' 57.64\" N" - "84 deg 23' 50.68\" W" """ return LatLon.string2latlon(lat, lon, "d% deg %m%' %S%\" %H") def distance_to_bofa(latlon): return latlon.distance(LATLON_BOFA) if __name__ == '__main__': lat, lon = sys.argv[1:] latlon = get_exif_latlon(lat, lon) print "Latitude: %s" % latlon.lat print "Longitude: %s" % latlon.lon distance = distance_to_bofa(latlon) print "Distance to BofA Building: %s km" % distance
This file contains 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
 #!/bin/bash filename="\$1" if [ -z "\$filename" ] then echo "Enter filename dep!" exit 1 fi # Just grepping for "GPS L" would yield the following: # # GPS Longitude Ref : West # GPS Latitude Ref : North # GPS Latitude : 33 deg 45' 49.37" N # GPS Longitude : 84 deg 21' 24.34" W exiftool "\$filename" |grep "GPS L" |grep -v Ref
This file contains 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
 #!/bin/bash # Use this file to get from image -> exif lat/lon -> distance filename="\$1" echo "Filename: \$filename" lat=\$(./exif-gps.sh "\$filename" | cut -d':' -f2 | head -n1) lon=\$(./exif-gps.sh "\$filename" | cut -d':' -f2 | tail -n1) ./distance.py "\$lat" "\$lon"