Last active
June 2, 2017 09:50
-
-
Save Deliaz/716f686153b0d97bd0fda9ec1d54e6b8 to your computer and use it in GitHub Desktop.
Get a screenshot from video
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
/** | |
* 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