Created
July 12, 2017 17:17
-
-
Save bertani/f4eb703d6bd19cb8991bb9c67b8d7e45 to your computer and use it in GitHub Desktop.
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
function findEXIFinJPEG(file) { | |
var dataView = new DataView(file); | |
if (debug) console.log("Got file of length " + file.byteLength); | |
if ((dataView.getUint8(0) != 0xFF) || (dataView.getUint8(1) != 0xD8)) { | |
if (debug) console.log("Not a valid JPEG"); | |
return false; // not a valid jpeg | |
} | |
var offset = 2, | |
length = file.byteLength, | |
marker; | |
var exifs = []; | |
while (offset < length) { | |
if (dataView.getUint8(offset) != 0xFF) { | |
if (debug) console.log("Not a valid marker at offset " + offset + ", found: " + dataView.getUint8(offset)); | |
return false; // not a valid marker, something is wrong | |
} | |
marker = dataView.getUint8(offset + 1); | |
if (debug) console.log(marker); | |
// we could implement handling for other markers here, | |
// but we're only looking for 0xFFE1 for EXIF data | |
if (marker == 225) { | |
if (debug) console.log("Found 0xFFE1 marker"); | |
exifs.push(readEXIFData(dataView, offset + 4, dataView.getUint16(offset + 2) - 2)); | |
offset += 2 + file.getShortAt(offset+2, true); | |
} else { | |
offset += 2 + dataView.getUint16(offset+2); | |
} | |
} | |
return exifs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment