-
-
Save parzibyte/eec73b40cd98ae9d0e392b4bccf735f3 to your computer and use it in GitHub Desktop.
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
$boton.addEventListener("click", function(){ | |
//Pausar reproducción | |
$video.pause(); | |
//Obtener contexto del canvas y dibujar sobre él | |
var contexto = $canvas.getContext("2d"); | |
$canvas.width = $video.videoWidth; | |
$canvas.height = $video.videoHeight; | |
contexto.drawImage($video, 0, 0, $canvas.width, $canvas.height); | |
var foto = $canvas.toDataURL(); //Esta es la foto, en base 64 | |
$estado.innerHTML = "Enviando foto. Por favor, espera..."; | |
var xhr = new XMLHttpRequest(); | |
xhr.open("POST", "./guardar_foto.php", true); | |
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); | |
xhr.send(encodeURIComponent(foto)); //Codificar y enviar | |
xhr.onreadystatechange = function() { | |
if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) { | |
console.log("La foto fue enviada correctamente"); | |
$estado.innerHTML = "Foto guardada con éxito. Puedes verla <a target='_blank' href='./" + xhr.responseText + "'> aquí</a>"; | |
} | |
} | |
//Reanudar reproducción | |
$video.play(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment