Skip to content

Instantly share code, notes, and snippets.

@Deliaz
Last active June 2, 2017 09:50
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 Deliaz/716f686153b0d97bd0fda9ec1d54e6b8 to your computer and use it in GitHub Desktop.
Save Deliaz/716f686153b0d97bd0fda9ec1d54e6b8 to your computer and use it in GitHub Desktop.
Get a screenshot from video
/**
* Takes a screenshot from video.
* @param videoEl {Element} Video element
* @param scale {Number} Screenshot scale (default = 1)
* @returns {Element} Screenshot image element
*/
function getScreenshot(videoEl, scale) {
scale = scale || 1;
const canvas = document.createElement("canvas");
canvas.width = videoEl.clientWidth * scale;
canvas.height = videoEl.clientHeight * scale;
canvas.getContext('2d').drawImage(videoEl, 0, 0, canvas.width, canvas.height);
const image = new Image()
image.src = canvas.toDataURL();
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment