Last active
October 9, 2019 06:11
-
-
Save jsuryahyd/c9b0f2ae1e1806d8c5cd32c2cc152d9b to your computer and use it in GitHub Desktop.
Extract metadata from image using exif-js; has drag-drop box to drop image into, and shows metadata if any exists.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
<title>EXIF example with inline EXIF info</title> | |
</head> | |
<body> | |
<br /> | |
<br /> | |
<br /> | |
<input type="file" id="fileInput" hidden /> | |
<div id="dropzone"> | |
<h3 | |
style="font-family: Arial, Helvetica, sans-serif;font-size: 24px;color:#e3e3e3" | |
> | |
Drop Here | |
</h3> | |
<img src="" id="image" /><br /> | |
</div> | |
<pre id="img3WithXmpMetaData"></pre> | |
<!-- <img src="./img.jpg" height="150px" width="150px" /> --> | |
<!-- <script type="text/javascript" src="./exif.min-2.3.0.js"></script> --> | |
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/exif-js"></script> | |
<script> | |
"use strict"; | |
window.onload = () => { | |
var img = document.getElementById("image"); | |
// getExif(img); | |
let dropzone = document.getElementById("dropzone"); | |
const fileInput = document.getElementById("fileInput"); | |
dropzone.ondragover = e => { | |
e.preventDefault(); | |
}; | |
dropzone.ondrop = e => { | |
e.preventDefault(); | |
// console.log(e); | |
fileInput.files = e.dataTransfer.files; | |
var files = e.dataTransfer.files[0]; | |
img.src = URL.createObjectURL( | |
new Blob([e.dataTransfer.files[0]], { type: "image/jpeg" }) | |
); | |
img.classList.add("show"); | |
}; | |
img.onload = function(e) { | |
getExif(this); | |
}; | |
}; | |
function getExif(img) { | |
if (!img) return console.error("no image"); | |
// EXIF.enableXmp(); | |
EXIF.getData(img, function() { | |
var allMetaData = EXIF.getAllTags(this); | |
var img3WithXmpMetaData = document.getElementById( | |
"img3WithXmpMetaData" | |
); | |
img3WithXmpMetaData.innerHTML = JSON.stringify( | |
allMetaData, | |
null, | |
"\t" | |
).replace(/\u0000/g, ""); | |
}); | |
} | |
</script> | |
</body> | |
<style> | |
#image { | |
width: 200px; | |
height: 200px; | |
display: none; | |
border-radius: 6px; | |
} | |
#image.show { | |
display: initial; | |
position: absolute; | |
left: 0; | |
top: 0;z-index: 100; | |
} | |
#dropzone { | |
position: relative; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
width: 200px; | |
height: 200px; | |
border: 1px dashed black; | |
border-radius: 6px; | |
} | |
</style> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment