Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 5, 2019 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/eec73b40cd98ae9d0e392b4bccf735f3 to your computer and use it in GitHub Desktop.
Save parzibyte/eec73b40cd98ae9d0e392b4bccf735f3 to your computer and use it in GitHub Desktop.
$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