Skip to content

Instantly share code, notes, and snippets.

@dearfrankg
Last active December 12, 2015 07:38
Show Gist options
  • Save dearfrankg/4737640 to your computer and use it in GitHub Desktop.
Save dearfrankg/4737640 to your computer and use it in GitHub Desktop.
// credit: http://snipplr.com/view.php?codeview&id=56433
//
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET",'favicon.ico',false);
xmlhttp.overrideMimeType('text/plain; charset=x-user-defined');
xmlhttp.send();
var data = '';
for ( var i = 0; i < xmlhttp.responseText.length; i++ ) data += String.fromCharCode( ( xmlhttp.responseText[ i ].charCodeAt(0) & 0xff ) );
// Convert raw data to base64
data = btoa( data );
var base64src='data:image/jpg;base64,'+data; // change the MIME type according to content
document.getElementById("foo").src = base64src;
console.log(base64src);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment