From 79486d9734bf9e5f440176c54adcd2972f349130 Mon Sep 17 00:00:00 2001 From: Jeremy Calvert Date: Sat, 20 May 2023 11:16:28 -0700 Subject: [PATCH 1/3] Seems to be working to parse GPS out of EXIF data within image. --- public/assets/drag-and-drop.js | 59 ++++++++++++++++++++++------------ views/partials/footer.ejs | 3 ++ 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/public/assets/drag-and-drop.js b/public/assets/drag-and-drop.js index 4a0e48c..c1282ba 100644 --- a/public/assets/drag-and-drop.js +++ b/public/assets/drag-and-drop.js @@ -1,34 +1,53 @@ +function convertDMSToDD([degrees, minutes, seconds]) { + return degrees + minutes / 60 + seconds / 3600; +} + function readURL(input) { - if (input.files && input.files[0]) { + if (input.files && input.files[0]) { + var reader = new FileReader(); - var reader = new FileReader(); + reader.onload = function (e) { + $('.image-upload-wrap').hide(); - reader.onload = function(e) { - $('.image-upload-wrap').hide(); + $('.file-upload-image').attr('src', e.target.result); + $('.file-upload-content').show(); - $('.file-upload-image').attr('src', e.target.result); - $('.file-upload-content').show(); + $('.image-title').html(input.files[0].name); - $('.image-title').html(input.files[0].name); - }; + var img = document.createElement('img'); + img.src = e.target.result; - reader.readAsDataURL(input.files[0]); + // Render thumbnail. + img.onload = function () { + EXIF.getData(img, function () { + var allMetaData = EXIF.getAllTags(this); + var allMetaDataSpan = document.getElementById('allMetaDataSpan'); + // allMetaDataSpan.innerHTML = JSON.stringify(allMetaData, null, '\t'); + var lat = convertDMSToDD(EXIF.getTag(this, 'GPSLatitude')); + var long = convertDMSToDD(EXIF.getTag(this, 'GPSLongitude')); + $('#lat').val(lat); + $('#long').val(long); + console.log(`lat: ${lat}, long: ${long}`); + }); + }; + }; - } else { - removeUpload(); - } + reader.readAsDataURL(input.files[0]); + } else { + removeUpload(); + } } function removeUpload() { - $('.file-upload-input').replaceWith($('.file-upload-input').clone()); - $('.file-upload-content').hide(); - $('.image-upload-wrap').show(); + $('.file-upload-input').replaceWith($('.file-upload-input').clone()); + $('.file-upload-content').hide(); + $('.image-upload-wrap').show(); } -$('.image-upload-wrap').bind('dragover', function() { - $('.image-upload-wrap').addClass('image-dropping'); +$('.image-upload-wrap').bind('dragover', function () { + $('.image-upload-wrap').addClass('image-dropping'); }); -$('.image-upload-wrap').bind('dragleave', function() { - $('.image-upload-wrap').removeClass('image-dropping'); -}); \ No newline at end of file +$('.image-upload-wrap').bind('dragleave', function () { + $('.image-upload-wrap').removeClass('image-dropping'); +}); diff --git a/views/partials/footer.ejs b/views/partials/footer.ejs index 26989ea..0f13f80 100644 --- a/views/partials/footer.ejs +++ b/views/partials/footer.ejs @@ -17,6 +17,9 @@ + + + From 24d1f4f2f91e0aa8b9a72990a29a52655945697e Mon Sep 17 00:00:00 2001 From: Jeremy Calvert Date: Sat, 20 May 2023 12:44:07 -0700 Subject: [PATCH 2/3] Negative because it's west longitude, apparently. --- public/assets/drag-and-drop.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/assets/drag-and-drop.js b/public/assets/drag-and-drop.js index c1282ba..265efe2 100644 --- a/public/assets/drag-and-drop.js +++ b/public/assets/drag-and-drop.js @@ -24,7 +24,7 @@ function readURL(input) { var allMetaDataSpan = document.getElementById('allMetaDataSpan'); // allMetaDataSpan.innerHTML = JSON.stringify(allMetaData, null, '\t'); var lat = convertDMSToDD(EXIF.getTag(this, 'GPSLatitude')); - var long = convertDMSToDD(EXIF.getTag(this, 'GPSLongitude')); + var long = -convertDMSToDD(EXIF.getTag(this, 'GPSLongitude')); // Negative because it's west longitude $('#lat').val(lat); $('#long').val(long); console.log(`lat: ${lat}, long: ${long}`); From 693e4c30bf4bf561f658d2ab2adf6a8d4e661941 Mon Sep 17 00:00:00 2001 From: Jeremy Calvert Date: Mon, 22 May 2023 08:44:08 -0700 Subject: [PATCH 3/3] Fix lazy-bug. --- public/assets/drag-and-drop.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/public/assets/drag-and-drop.js b/public/assets/drag-and-drop.js index 265efe2..34bc209 100644 --- a/public/assets/drag-and-drop.js +++ b/public/assets/drag-and-drop.js @@ -1,5 +1,9 @@ -function convertDMSToDD([degrees, minutes, seconds]) { - return degrees + minutes / 60 + seconds / 3600; +function convertDMSToDD([degrees, minutes, seconds], ref) { + decimal_degrees = degrees + minutes / 60 + seconds / 3600; + if (ref == 'S' || ref == 'W') { + decimal_degrees = -decimal_degrees; + } + return decimal_degrees; } function readURL(input) { @@ -23,8 +27,14 @@ function readURL(input) { var allMetaData = EXIF.getAllTags(this); var allMetaDataSpan = document.getElementById('allMetaDataSpan'); // allMetaDataSpan.innerHTML = JSON.stringify(allMetaData, null, '\t'); - var lat = convertDMSToDD(EXIF.getTag(this, 'GPSLatitude')); - var long = -convertDMSToDD(EXIF.getTag(this, 'GPSLongitude')); // Negative because it's west longitude + var lat = convertDMSToDD( + EXIF.getTag(this, 'GPSLatitude'), + EXIF.getTag(this, 'GPSLatitudeRef') + ); + var long = convertDMSToDD( + EXIF.getTag(this, 'GPSLongitude'), + EXIF.getTag(this, 'GPSLongitudeRef') + ); $('#lat').val(lat); $('#long').val(long); console.log(`lat: ${lat}, long: ${long}`);