Question:
How can I save an uploaded image to localStorage, then display it on a subsequent page?
Answer:
Saving the Image
function getBase64Image(img) { var canvas = document.createElement("canvas"); canvas.width = img.width; canvas.height = img.height; var ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0); var dataURL = canvas.toDataURL("image/png"); return dataURL.replace(/^data:image\/(png|jpg);base64,/, ""); }
Displaying the Image
The above is the detailed content of How to Save and Display Images Using LocalStorage?. For more information, please follow other related articles on the PHP Chinese website!