0

Am getting an error while finding the exif information of an image (base64 image data):

Exif.getData(path, () => {
    const tag = Exif.getTag(this, 'Orientation');
    console.log(tag);
});

ReferenceError: self is not defined

/usr/local/lib/node_modules/exif-js/exif.js:931
if ((self.Image && img instanceof self.Image)
^

can anyone help

Anand Paul
  • 355
  • 5
  • 17

2 Answers2

0

Are you executing this snippet in Client side JS or Node.js ?

Currently exif.js is developed based on the self object. It supports only client side Javascript.

Register exif.js after window load, Attached sample snippet for reference.

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");
        var makeAndModel = document.getElementById("makeAndModel");
        makeAndModel.innerHTML = `${make} ${model}`;
    });

    var img2 = document.getElementById("img2");
    EXIF.getData(img2, function() {
        var allMetaData = EXIF.getAllTags(this);
        var allMetaDataSpan = document.getElementById("allMetaDataSpan");
        allMetaDataSpan.innerHTML = JSON.stringify(allMetaData, null, "\t");
    });
}
Ashok JayaPrakash
  • 2,115
  • 1
  • 16
  • 22
0

Exif parser works perfectly in server side. https://www.npmjs.com/package/exif-parser

Anand Paul
  • 355
  • 5
  • 17