Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

mozilla-b2g/exif-parser

Repository files navigation

exif-parser

It provides an API to read and write EXIF metadata from jpeg images.

Try it

Use it

Download the library and include it in your html.

<script src="js/jpeg.js"></script>

The following code loads a file, reads the exif metadata, modifies the rotation tag and creates a new blob with the new metadata.

<script>

  var readExif = function(fileBlob) {
    JPEG.readExifMetaData(fileBlob, function(error, metaData) {
      console.log(JSON.stringify(metaData))
    });
  };

  var writeExif = function(fileBlob) {
    JPEG.writeExifMetaData(
      fileBlob,
      {"Orientation" : 1},
      function(error, modifiedBlob) {
        // Process modified file
      });
  };

  var processImage = function() {
    var request = new XMLHttpRequest();
    request.open("GET", "/exif-parser/examples/images/sample.jpg", true);
    request.responseType = "arraybuffer";
    request.onload = function (event) {
      var arrayBuffer = request.response; // Note: not request.responseText
      var blob = new Blob([arrayBuffer],{type: "image/jpeg"});
      readExif(blob);
      writeExif(blob);
    };
    request.send(null);
  };

  processImage();

</script>

Test it