I have different types of image content in base64 format in javascript, like:
a png file: "iVBORw0KGgoAAAANSUhEUgAABQAAAAL4CAYAAAAkgloNAAAgA......."
a jpeg file: "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDA......"
similarly, there can be other images like GIF, BMP, etc.
I need a way to determine the image type based on the content. I understand there are headers for each file type and I can refer it to determine the image content type. Example Reference: http://en.wikipedia.org/wiki/Portable_Network_Graphics#Technical_details.
But does anyone know of a library or other technique that will do the trick in a more smarter way? I can use any of the HTML5 features if required.
The main intent is to render the image on the screen. For that I use dataURI pattern, . I have image content, all I need is to put the right value in the "data:image/png" part of the url.
There's lots of javascript base64 decoders, (related question), just decode the first 4 or 5 letters and they should contain the filetype.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With