Created
November 22, 2017 02:24
-
-
Save fegemo/f8895a21247e6afafbeef2d6b129c752 to your computer and use it in GitHub Desktop.
Usando html2canvas para gerar uma imagem "pixelada" (nítida), e não desfocada
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
let baixarEl = document.querySelector('#baixar'); | |
let avatarEl = document.querySelector('#avatar-preview'); | |
baixarEl.addEventListener('click', function(e) { | |
html2canvas(avatarEl, { | |
onrendered: function(canvas) { | |
let contextoGrafico = canvas.getContext('2d'); | |
contextoGrafico.webkitImageSmoothingEnabled = false; | |
contextoGrafico.mozImageSmoothingEnabled = false; | |
contextoGrafico.imageSmoothingEnabled = false; | |
let imagemCodificadaEmURL = canvas.toDataURL(); | |
let link = document.createElement('a'); | |
link.download = 'avatar.png'; | |
link.href = imagemCodificadaEmURL; | |
document.body.appendChild(link); | |
link.click(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment