Skip to content

Commit

Permalink
add webcam save pic button
Browse files Browse the repository at this point in the history
  • Loading branch information
bleeptrack committed Sep 30, 2024
1 parent 1814fca commit 8461b36
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion static/VectorizerCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ export class VectorizerCanvas extends HTMLElement {
width: 48px;
}
}
#photo-container{
display: flex;
flex-direction: row;
align-items: center;
}
</style>
Expand Down Expand Up @@ -466,7 +472,10 @@ export class VectorizerCanvas extends HTMLElement {
<div id="canvas-container"></div>
<video id="webcam"></video>
<canvas id="edge-canvas"></canvas>
<button id="stop-webcam" class="scribble">take photo</button>
<div id="photo-container">
<button id="stop-webcam" class="scribble">take photo</button>
<button id="download-photo" class="scribble">save photo for later</button>
</div>
`

this.video = this.shadow.getElementById("webcam")
Expand Down Expand Up @@ -502,6 +511,26 @@ export class VectorizerCanvas extends HTMLElement {
paper.view.onFrame = () => {}
this.activateImage(this.video)
})

this.shadow.getElementById("download-photo").addEventListener("click", () => {

const tempCanvas = document.createElement('canvas');
tempCanvas.width = this.vidw;
tempCanvas.height = this.vidh;
const tempCtx = tempCanvas.getContext('2d');

tempCtx.drawImage(this.video, 0, 0, this.vidw, this.vidh);
const dataURL = tempCanvas.toDataURL('image/jpeg');

const link = document.createElement('a');
link.href = dataURL;
const now = new Date();
const formattedDate = now.toISOString().replace(/:/g, '-').replace(/\..+/, '');
link.download = `tinqta_photo_${formattedDate}.jpg`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
})



Expand Down

0 comments on commit 8461b36

Please sign in to comment.