It provides an API to read and write EXIF metadata from jpeg images.
- Demo.
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>