I have a PHP script that can encode a PNG image to a Base64 string.
I\'d like to do the same thing using JavaScript. I know how to open files, but I\'m not sure how
While a bit more work, if you want a high performance native solution there are some HTML5 functions you can use.
If you can get your data into a Blob, then you can use the FileReader.readAsDataURL() function to get a data://
URL and chop off the front of it to get at the base64 data.
You may have to do further processing however to urldecode the data, as I'm not sure whether +
characters are escaped or not for the data://
URL, but this should be pretty trivial.