title: Determine image type from base 64 content
body: <p>I have different types of image content in base64 format in javascript, like:</p>
  <p>a png file: &quot;iVBORw0KGgoAAAANSUhEUgAABQAAAAL4CAYAAAAkgloNAAAgA.......&quot;</p>
  <p>a jpeg file: &quot;/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDA......&quot;</p>
  <p>similarly, there can be other images like GIF, BMP, etc.</p>
  <p>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: <a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics#Technical_details" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Portable_Network_Graphics#Technical_details</a>.</p>
  <p>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.</p>
  <p>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 &quot;data:image/png&quot; part of the url.</p>