Does anyone know of any simple javascript that I can use to turn a base64 string into an image (jpg format preferably), so that I can save the image to a file? This is for a signature pad application. I can get the signature into a base64 format, but need to save the signature as an image file to use for embedding into a Crystal Report.
Asked
Active
Viewed 3,558 times
1 Answers
-4
I have tried this method in a JSP page to print the image from a base64 string, I guess this should hold good for javascript too. Do not have sample data for now to verify, but here's how I would try it.
var oImg=document.createElement("img");
var baseString = null; //the base64 string you have
var imsc = 'data:image/jpg;base64, '+baseString;
oImg.setAttribute('src', imsc);
document.body.appendChild(oImg);

Aakash Jain
- 730
- 1
- 12
- 31
-
I have this working so that the new image displays on the page (as in the above example). What I really need is for the image to save to my computer. Any ideas on how I can make that part of it work in JavaScript? – wedge47 Nov 26 '14 at 15:40
-
You can convert that base64String to canvas and then download that canvas http://stackoverflow.com/questions/17397319/save-canvas-as-jpg-to-desktop & to convert the data to canvas this will help http://stackoverflow.com/questions/4409445/base64-png-data-to-html5-canvas – Aakash Jain Nov 27 '14 at 04:55