I'm looking for a way to convert a hex image (for example a jpg in hex form) back to base64 in order to display the image in a web page.
I have been using the code below for smaller images but it fails for larger images with a max call stack exceeded error.
src below is the source of the image in hex format.
test.img = new Image();
test.img.src = "data:image/jpg; base64," + hexToBase64(src);
function hexToBase64(str) {
return btoa(String.fromCharCode.apply(null, str.replace(/\r|\n/g, "").replace(/([\da-fA-F]{2}) ?/g, "0x$1 ").replace(/ +$/, "").split(" ")));
}