So I got a code for encoding an image to a base64 one..
function toDataUrl(url, callback) {
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function() {
var reader = new FileReader();
reader.onloadend = function() {
callback(reader.result);
}
reader.readAsDataURL(xhr.response);
};
xhr.open('GET', url);
xhr.send();
}
toDataUrl('img/no_image_icon.png', function(base64Img) {
console.log(base64Img); // remove the data:image/png;base64, in the beginning
});
This code works though I want to remove the data:image/png;base64,
in the beginning of the generated base64Img
. And also, how can I access it outside of the function? Like example
toDataUrl('img/no_image_icon.png', function(base64Img) {
var accessOutside = base64Img; // remove the data:image/png;base64, in the beginning
});
var newVariable = accessOutside;
Any help would be much appreciated.