Données EXIF

Bibliothèques

Deux bibliothèques sont à charger: binaryajax.js et exif.js.

L'image doit avoir un attribut exif="true"

Un objet global EXIF est créé. Ses méthodes:

EXIF.getTag(oImg , 'Model')
récupère la valeur d'un tag
EXIF.pretty(oImg)
retourne une châine avec la valeur de tous les tags EXIF
EXIF.getGPSPosition(oImg)
Retourne un vecteur [Lat,Long] (degrés décimaux)

Tags EXIF

GPSLatitude
tableau 3 positions DMS
GPSLongitude
idem
GPSLatitudeRef
N ou S
GPSLongitudeRef
W ou E

Coordonnées

var oImg = new Image(); oImg.onload = function() { EXIF.getData(oImg, function() { var aLat = EXIF.getTag(oImg, "GPSLatitude"); var aLong = EXIF.getTag(oImg, "GPSLongitude"); if (!(aLat && aLong)) return; // no GPS info // convert from deg/min/sec to decimal for Google var strLatRef = EXIF.getTag(oImg, "GPSLatitudeRef") || "N"; var strLongRef = EXIF.getTag(oImg, "GPSLongitudeRef") || "W"; var fLat = (aLat[0] + aLat[1]/60 + aLat[2]/3600) * (strLatRef == "N" ? 1 : -1); var fLong = (aLong[0] + aLong[1]/60 + aLong[2]/3600) * (strLongRef == "W" ? -1 : 1); // center the google map and add a marker oMap.setCenter(new GLatLng(fLat, fLong), 13); oMarker = new GMarker(new GLatLng(fLat, fLong)); oMap.addOverlay(oMarker); } ); } oImg.src = "my_gps_tagged_photo.jpg";

Exemple

Clic gauche et droit