9

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.

4

1 回答 1

2

有很多 javascript base64 解码器,(相关问题),只需解码前 4 或 5 个字母,它们应该包含文件类型。

于 2012-04-24T20:25:07.487 回答