Last active
December 14, 2016 03:11
-
-
Save Joseph7451797/84b5b013f00a5d9ac215db8f8945c9a3 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
var EXIF = require('exif-js'); | |
var $input = $('#uploadImage'); | |
function base64ToArrayBuffer (base64) { | |
base64 = base64.replace(/^data\:([^\;]+)\;base64,/gmi, ''); | |
var binaryString = atob(base64); | |
var len = binaryString.length; | |
var bytes = new Uint8Array(len); | |
for (var i = 0; i < len; i++) { | |
bytes[i] = binaryString.charCodeAt(i); | |
} | |
return bytes.buffer; | |
} | |
$input.on('change', function() { | |
var file = this.files[0]; | |
var reader = new FileReader(); | |
reader.onload = function (e) { | |
var exif = EXIF.readFromBinaryFile(base64ToArrayBuffer(this.result)), html = []; | |
html.push('<div>'); | |
for(var key in exif) { | |
var val = exif[key]; | |
html.push('<p>', key, ' : <em>'); | |
html.push(val, '</em></p>'); | |
} | |
html.push('</div>'); | |
document.getElementById('imgInfo').innerHTML = html.join(''); | |
var preview = '<div class="bg" style="background-image:url(' + e.target.result + ')"></div>'; | |
$(preview).insertAfter('#uploadImage'); | |
} | |
reader.readAsDataURL(file); | |
//reader.readAsBinaryString(file); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment