Skip to content

Commit

Permalink
Add GPS coordintes helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
hMatoba committed May 20, 2017
1 parent f8fc3c8 commit eb3c91e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/sample.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,19 @@ Generates Rotated JPEG

document.getElementById("files").onchange = previewJpeg;

GPS Coordinates
---------------

::

var lat = 59.43553989213321;
var lng = 24.73842144012451;
gpsIfd[piexif.GPSIFD.GPSLatitudeRef] = lat < 0 ? 'S' : 'N';
gpsIfd[piexif.GPSIFD.GPSLatitude] = piexif.GPSHelper.degToDmsRational(lat);
gpsIfd[piexif.GPSIFD.GPSLongitudeRef] = lng < 0 ? 'W' : 'E';
gpsIfd[piexif.GPSIFD.GPSLongitude] = piexif.GPSHelper.degToDmsRational(lng);


Node.js
-------

Expand Down
12 changes: 12 additions & 0 deletions piexif.js
Original file line number Diff line number Diff line change
Expand Up @@ -2445,6 +2445,18 @@ SOFTWARE.
that.InteropIFD = {
InteroperabilityIndex:1,
};

that.GPSHelper = {
degToDmsRational:function (degFloat) {
var minFloat = degFloat % 1 * 60;
var secFloat = minFloat % 1 * 60;
var deg = Math.floor(degFloat);
var min = Math.floor(minFloat);
var sec = Math.round(secFloat * 100);

return [[deg, 1], [min, 1], [sec, 100]];
}
};


if (typeof exports !== 'undefined') {
Expand Down
8 changes: 8 additions & 0 deletions samples/CanvasSample.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@
exifIfd[piexif.ExifIFD.LensSpecification] = [[1, 1], [1, 1], [1, 1], [1, 1]];
gpsIfd[piexif.GPSIFD.GPSVersionID] = [7, 7, 7, 7];
gpsIfd[piexif.GPSIFD.GPSDateStamp] = "1999:99:99 99:99:99";

var lat = 59.43553989213321;
var lng = 24.73842144012451;
gpsIfd[piexif.GPSIFD.GPSLatitudeRef] = lat < 0 ? 'S' : 'N';
gpsIfd[piexif.GPSIFD.GPSLatitude] = piexif.GPSHelper.degToDmsRational(lat);
gpsIfd[piexif.GPSIFD.GPSLongitudeRef] = lng < 0 ? 'W' : 'E';
gpsIfd[piexif.GPSIFD.GPSLongitude] = piexif.GPSHelper.degToDmsRational(lng);

var exifObj = {"0th":zerothIfd, "Exif":exifIfd, "GPS":gpsIfd};

// get exif binary as "string" type
Expand Down

0 comments on commit eb3c91e

Please sign in to comment.