Created
June 9, 2017 19:46
-
-
Save giniedp/5f7dca64e10ecea1d45c7fad55c012d3 to your computer and use it in GitHub Desktop.
Capture screenshot from html video element
This file contains hidden or 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
| (function(window) { | |
| 'use strict'; | |
| window.snapshot = function snap(video, width, height, download) { | |
| video = video || window.document.getElementsByTagName('video')[0]; | |
| width = video.width || video.videoWidth; | |
| height = video.height || video.videoHeight; | |
| var canvas = window.document.createElement('canvas'); | |
| canvas.width = width; | |
| canvas.height = height; | |
| var context = canvas.getContext('2d'); | |
| context.fillRect(0, 0, width, height); | |
| context.drawImage(video, 0, 0, width, height); | |
| var dataURI = canvas.toDataURL('image/jpeg'); | |
| if (download) { | |
| dataURI = dataURI.replace('image/jpeg', 'image/octet-stream'); | |
| } | |
| window.open(dataURI, '_blank').focus(); | |
| }; | |
| }(this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment