Merge pull request #7 from j-calvert/exif-parse

Seems to be working to parse GPS out of EXIF data within image.
This commit is contained in:
moom0o 2023-06-01 22:13:39 -04:00 committed by GitHub
commit 3b1e0e0c35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 20 deletions

View File

@ -1,19 +1,48 @@
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) { 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'),
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}`);
});
};
}; };
reader.readAsDataURL(input.files[0]); reader.readAsDataURL(input.files[0]);
} else { } else {
removeUpload(); removeUpload();
} }
@ -25,10 +54,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>