Last active
November 9, 2015 09:23
-
-
Save semagarcia/f9ecdaf0f76a2fa3ef9d to your computer and use it in GitHub Desktop.
How to convert an image into base64 string
This file contains 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
<img id="image" src="http://www.gravatar.com/avatar/90348ht093409g7wetdgf?s=128&d=identicon&r=PG"> | |
<canvas id="canvasElement"/> | |
<div id="base64string" /> |
This file contains 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
var canvasEl = document.getElementById("canvasElement"); | |
var ctx = canvasEl.getContext("2d"); | |
var img = document.getElementById("image"); | |
ctx.drawImage(img, 15, 15); | |
alert(canvasEl.toDataURL()); | |
document.getElementById('base64string').innerHTML = img; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment