I'm developing a simple Chromium extension that reads EXIF data and shows to the user but in the library I'm using (which is Exif.js), I feel like there are things I'm not doing correctly because the output is always an empty string and undefined. Here's the code:
const img = document.getElementById("someImage");
window.onload = getExif(img);
function getExif(file) {
try {
EXIF.getData(file, function () {
if (file) {
var make = EXIF.getTag(this, "Make");
var model = EXIF.getTag(this, "Model");
var allMetaData = EXIF.pretty(this);
console.log(JSON.stringify(allMetaData, null, 2));
console.log(make, model);
} else {
console.error("EXIF data has not been found or incomplete.");
}
});
} catch (error) {
console.error("Error reading EXIF data", error);
}
}
"make" and "model" always returns an "undefined" from an image I'm using through classical const img = document.getElementById(someImage)
in popup.html as well as allMetaData returning and empty string.
I've followed the "Usage" section in the documentation but nothing appears to be fixing this.
@gokacinlar; This works on my end, you can try to run the code snippet;
<html lang="en">
<img src="https://raw.githubusercontent.com/exif-js/exif-js/master/example/DSCN0614_small.jpg" id="img1" />
<div id="exifData">Make : <span id="imgMake"></span> Model : <span id="imgModel"></span></div>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/exif-js"></script>
<script type="text/javascript">
window.onload=getExif;
function getExif() {
var img1 = document.getElementById("img1");
EXIF.getData(img1, function() {
var make = EXIF.getTag(this, "Make");
var model = EXIF.getTag(this, "Model");
document.getElementById("imgMake").innerHTML = make;
document.getElementById("imgModel").innerHTML= model;
});
}
</script>
</html>