Skip to content

Instantly share code, notes, and snippets.

@mariorcardoso
Created April 28, 2022 13:15
Show Gist options
  • Save mariorcardoso/f00a86c22c384fe54f303f26818ae330 to your computer and use it in GitHub Desktop.
Save mariorcardoso/f00a86c22c384fe54f303f26818ae330 to your computer and use it in GitHub Desktop.
const generateImageWithCanvas = (
track: MediaStreamTrack,
videoElem: HTMLVideoElement
) => {
const canvas = document.createElement("canvas");
const { width, height } = track.getSettings();
canvas.width = width || 100;
canvas.height = height || 100;
canvas.getContext("2d")?.drawImage(videoElem, 0, 0);
const image = canvas.toDataURL("image/png");
return image;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment