7

I've seen:

 src="data:image/png;base64,iVBORw0KG..."

or

src="data:image/jpeg;base64,LzlqLz..."

or

src="data:image/gif;base64,R0lGODl..."

Is the image type compulsory, or is there some way I can get the browser to figure it out and pass something like:

src="data:image;base64,R0lGODlh...
David
  • 15,652
  • 26
  • 115
  • 156
  • You can write some code to look at the first byte of data to figure out the image type. [look here](http://stackoverflow.com/a/9899096/1990505) – Vikram Deshmukh Sep 24 '15 at 09:54
  • @VikramDeshmukh He will have to convert it to JavaScript tho – Stranded Kid Sep 24 '15 at 09:58
  • no, you need to pass a valid dataURL to use it as a source in the DOM, and that includes mime. – dandavis Sep 24 '15 at 10:00
  • even if you sniff the type, you still need to feed an img tag a dataURL that has the mime type in it, so why not just store it and avoid binary operations... – dandavis Sep 24 '15 at 10:01
  • I guess you guys are right, I was just wondering if there was an inbuilt way to do it. After all, src="123.png" will load even if 123 is actually a jpg image, in Chrome. But that's not very nice. – David Sep 24 '15 at 10:04

1 Answers1

0

i am sure, you need strore what is the type of the image. Probably with your file extension

Velkumar
  • 446
  • 1
  • 8
  • 20