Last active
August 29, 2015 14:04
-
-
Save dyjjones/71beb2ac7c294ab16871 to your computer and use it in GitHub Desktop.
Command line function for lat/lon of picture.
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/node | |
// neg = node exif geolocation, latitude and longitude | |
// Add to your path, then use as: neg.js [path to image] | |
// chmod +x this file on download, move to a path folder | |
// or add to path manually | |
var im = require('imagemagick'); | |
if (process.argv.length === 3) { | |
im.readMetadata(process.argv[2], function (err, metadata) { | |
if (err) throw err; | |
if (metadata.exif) { | |
if (metadata.exif.gpsLatitude && metadata.exif.gpsLongitude) { | |
console.log('Raw Latitude:\t\t', metadata.exif.gpsLatitude); | |
console.log('Raw Longitude:\t\t', metadata.exif.gpsLongitude); | |
var splitLat = metadata.exif.gpsLatitude.split(', '); | |
var splitLon = metadata.exif.gpsLongitude.split(', '); | |
var decimalLat = parseInt(splitLat[0].split('/')[0]) + | |
(parseInt(splitLat[1].split('/')[0]) / (60.0 * parseInt(splitLat[1].split('/')[1]))) + | |
(parseInt(splitLat[2].split('/')[0]) / (3600.0 * parseInt(splitLat[2].split('/')[1]))); | |
var decimalLon = parseInt(splitLon[0].split('/')[0]) + | |
(parseInt(splitLon[1].split('/')[0]) / (60.0 * parseInt(splitLon[1].split('/')[1]))) + | |
(parseInt(splitLon[2].split('/')[0]) / (3600.0 * parseInt(splitLon[2].split('/')[1]))); | |
console.log('Decimal Latitude:\t', decimalLat); | |
console.log('Decimal Longitude:\t', decimalLon); | |
} | |
else { | |
console.log('No latitude and longitude available.'); | |
} | |
} | |
else { | |
console.log('No exif data.'); | |
} | |
}); | |
} | |
else | |
console.log('Usage: `neg [path to image]`'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment