Skip to content

Instantly share code, notes, and snippets.

@GitHub30
Last active October 15, 2019 03:59
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 GitHub30/8a6ffa719f3e7c2b44e657947abe5364 to your computer and use it in GitHub Desktop.
Save GitHub30/8a6ffa719f3e7c2b44e657947abe5364 to your computer and use it in GitHub Desktop.
function takePhoto(video, mimeType = 'image/jpeg') {
return new Promise(resolve => {
video.animate({opacity: [0,1]}, 300);
const canvas = document.createElement('canvas');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
// TODO
// https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/getContext
// https://bugzilla.mozilla.org/show_bug.cgi?id=801176
canvas.getContext('2d').drawImage(video, 0, 0);
canvas.toBlob(resolve, mimeType);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment