2

I need to convert an image to base64 encoding. I know its very easy with canvas. but the problem is that it should also run in IE8. but IE8 dont support HTML5 so i can't do it using canvas. Is there any other method using javaScript to convert image to base64 ?

Thanks

sachin
  • 31
  • 1
  • 1
  • 3
  • find a binary ajax routine that works with IE8, and a js-coded btoa() polyfill and you're on your way. – dandavis Oct 11 '13 at 06:32

2 Answers2

2

Simple answer is no if this needs to be done on client side. The canvas element is the only way to convert an image to bitmap data or data-uris (and even then security restriction may apply preventing this).

You can maybe get around this using Flash but of course that would require the client to have Flash installed.

Or setting up an external web service where you can upload the image and have it return the data you need.

For IE8 and lower there are no options out of the box (exCanvas gives you canvas drawing capabilities but can't provide bitmap data which is needed here). Basically, for IE8 you will need a server.

1

There are some answers given here

How can you encode a string to Base64 in JavaScript?

have you tried any of them?

Community
  • 1
  • 1
gurvinder372
  • 66,980
  • 10
  • 72
  • 94
  • i was trying to do using solution of Sunny Milenov. i can successfully convert string to base64 using it. but i couldn't understand how to convert image using this. can you please help me ? – sachin Oct 11 '13 at 05:49
  • @sachin check this link http://dean.edwards.name/weblog/2005/06/base64-ie/ idea is to use img.src.slice(5); – gurvinder372 Oct 11 '13 at 05:57
  • The problem with this is I am not using back-end like php etc. I am implementing it in Salesforce. – sachin Oct 11 '13 at 06:04
  • @sachin you don't need to. If the image is already loaded, you need to do img.src.slice(5); – gurvinder372 Oct 11 '13 at 06:06