Created
July 2, 2021 20:46
-
-
Save arronmabrey/bf70d8ef70251b26c076e30a4b9b0e01 to your computer and use it in GitHub Desktop.
getBase64Image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,/, ""); | |
} | |
var base64 = getBase64Image(document.getElementById("imageid")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment