diff --git a/src/modules/04_checkin/views/Checkin.vue b/src/modules/04_checkin/views/Checkin.vue index 12138b7..9e92aba 100644 --- a/src/modules/04_checkin/views/Checkin.vue +++ b/src/modules/04_checkin/views/Checkin.vue @@ -72,7 +72,7 @@
@@ -98,45 +98,38 @@ color="blue-grey-3" />
-
-
+
- +
@@ -306,11 +299,6 @@ const canvas = ref(null); const hasPhoto = ref(true); const img = ref(); -const videoWidth = ref(335); -const videoHeight = ref(350); -const canvasWidth = ref(335); -const canvasHeight = ref(350); - function capturePhoto() { const videoElement = video.value; const canvasElement = canvas.value; @@ -323,7 +311,49 @@ function capturePhoto() { console.error("Canvas context not available"); return; } - context.drawImage(videoElement, 0, 0, 335, 270); + const desiredWidth = 189; + const desiredHeight = 190; + const zoomFactor = 10; + + const videoAspectRatio = videoElement.videoWidth / videoElement.videoHeight; + const canvasAspectRatio = desiredWidth / desiredHeight; + + let drawWidth, drawHeight; + + if (videoAspectRatio > canvasAspectRatio) { + drawWidth = desiredWidth * zoomFactor; + drawHeight = (desiredWidth * zoomFactor) / videoAspectRatio; + } else { + drawWidth = desiredHeight * zoomFactor * videoAspectRatio; + drawHeight = desiredHeight * zoomFactor; + } + + canvasElement.width = drawWidth; + canvasElement.height = drawHeight; + if (context) { + context.imageSmoothingEnabled = true; + context.imageSmoothingQuality = "high"; + } + + // context.drawImage( + // videoElement, + // 0, + // 0, + // canvasElement.width, + // canvasElement.height + // ); + context.drawImage( + videoElement, + 0, + 0, + videoElement.videoWidth, + videoElement.videoHeight, + 0, + 0, + drawWidth, + drawHeight + ); + //ไฟล์รูป const dataURL = canvasElement.toDataURL(".image/.png"); img.value = dataURL;