-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
30 lines (26 loc) · 907 Bytes
/
scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const video = document.querySelector('.handsome');
const canvas = document.querySelector('#paint');
const ctx = canvas.getContext('2d');
const strip = document.querySelector('.strip');
async function go() {
// first ask for get user media
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
video.srcObject = stream;
}
function takePhoto() {
console.log('Taking photo!');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
ctx.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
const data = canvas.toDataURL('image/jpeg');
console.log(data);
const link = document.createElement('a');
// link.href = data;
link.setAttribute('download', 'handsome');
link.innerHTML = `<img src="${data}" alt="Handsome Man" />`;
// strip.insertBefore(link, strip.firsChild);
detectCamImg(data);
}
go().catch(err => {
alert(err.message);
});