Last active
December 20, 2015 11:39
-
-
Save letanure/6125171 to your computer and use it in GitHub Desktop.
image to base64
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
function imageToBase64(URL) { | |
var imagem = new Image(); | |
imagem.src = URL; | |
imagem.onload = function () { | |
var canvas = document.createElement("canvas"); | |
canvas.width = this.width; | |
canvas.height = this.height; | |
var cvx = canvas.getContext("2d"); | |
cvx.drawImage(this, 0, 0); | |
var dataURL = canvas.toDataURL("image/png"); | |
console.log( dataURL.replace(/^data:image\/(png|jpg);base64,/, "")); | |
} | |
} | |
//ex | |
imageToBase64('http://jsfiddle.net/img/logo.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment