Seems to be working to parse GPS out of EXIF data within image.

This commit is contained in:
Jeremy Calvert 2023-05-20 11:16:28 -07:00
parent 2673bbe617
commit 79486d9734
2 changed files with 42 additions and 20 deletions

View File

@ -1,19 +1,38 @@
function convertDMSToDD([degrees, minutes, seconds]) {
return degrees + minutes / 60 + seconds / 3600;
}
function readURL(input) { 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) { reader.onload = function (e) {
$('.image-upload-wrap').hide(); $('.image-upload-wrap').hide();
$('.file-upload-image').attr('src', e.target.result); $('.file-upload-image').attr('src', e.target.result);
$('.file-upload-content').show(); $('.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;
// 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}`);
});
};
}; };
reader.readAsDataURL(input.files[0]); reader.readAsDataURL(input.files[0]);
} else { } else {
removeUpload(); removeUpload();
} }
@ -25,10 +44,10 @@ function removeUpload() {
$('.image-upload-wrap').show(); $('.image-upload-wrap').show();
} }
$('.image-upload-wrap').bind('dragover', function() { $('.image-upload-wrap').bind('dragover', function () {
$('.image-upload-wrap').addClass('image-dropping'); $('.image-upload-wrap').addClass('image-dropping');
}); });
$('.image-upload-wrap').bind('dragleave', function() { $('.image-upload-wrap').bind('dragleave', function () {
$('.image-upload-wrap').removeClass('image-dropping'); $('.image-upload-wrap').removeClass('image-dropping');
}); });

View File

@ -18,6 +18,9 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<!-- EXIF JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/exif-js/2.3.0/exif.js" integrity="sha512-bE9sOOprru4D2nRKDQSNvhdxw47Jd0r2s7QThKB/KkU5HEPuxsk9DbK+fYIMCYlCsXkwp6M87vj84sAtYWqxvw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<!-- Then Material JavaScript on top of Bootstrap JavaScript --> <!-- Then Material JavaScript on top of Bootstrap JavaScript -->
<script src="/assets/material/material.min.js"></script> <script src="/assets/material/material.min.js"></script>
</body> </body>