Search code examples
javascripthtmlimagebase64ascii

Create image from ascii value


I am new to base64 images. I have a problem that base64 images are not completely supported in IE8 or lower, with a limitation of 32Kb.

Finally, I got a function to convert base64 images to ascii code using javascript. However, I am not able to figure out how to show a img using ascii value of the image.

when we use base64 in img tag we write like this,

<img src="data:image/png;base64,iVBORw0K..." />

Therefore, I need something using which if I have an ascii code of an image, I can display it the similar way I am displaying base64 image image.


Solution

  • I think you misunderstand the limitations of IE8.

    IE8 only supports images with a maximum size of 32KB, not 32 bits. The only thing you can do about it is delivering images that are at most 32KB big. Or drop the support for IE8 is that is an option.

    In answer of your second question:

    set the src attribute of the image using JavaScript:

    function changeImage(dataAsBase64String)
    {
        image1.src = 'data:image/png;base64,' + dataAsBase64String;
    }