modified capture photo method logic in ocr

This commit is contained in:
dhanabalan
2025-10-24 17:37:51 +05:30
parent 8d49937a68
commit a3732936ac

View File

@@ -328,7 +328,7 @@ function cameraCapture() {
}, },
async capturePhoto() { async capturePhoto() {
const video = this.$refs.video; const video = this.$refs.video;
const canvas = this.$refs.canvas; const canvas = this.$refs.canvas;
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
@@ -340,30 +340,30 @@ function cameraCapture() {
const snapshot = this.$refs.snapshot; const snapshot = this.$refs.snapshot;
snapshot.src = canvas.toDataURL('image/png'); snapshot.src = canvas.toDataURL('image/png');
// ✅ Wait until the SNAPSHOT image loads before cropper!
snapshot.onload = () => { snapshot.onload = () => {
snapshot.classList.remove('hidden'); snapshot.classList.remove('hidden');
video.classList.add('hidden'); video.classList.add('hidden');
this.photoTaken = true; this.photoTaken = true;
this.stopCamera(); // ✅ Now camera turns off immediately this.stopCamera();
// ✅ Ensure previous cropper destroyed if (this.cropper) this.cropper.destroy();
if (this.cropper) {
this.cropper.destroy();
}
// ✅ Start Cropper only after image rendered requestAnimationFrame(() => {
this.cropper = new Cropper(snapshot, { this.cropper = new Cropper(snapshot, {
aspectRatio: NaN, aspectRatio: NaN,
dragMode: 'crop', dragMode: 'crop',
viewMode: 1, viewMode: 1,
autoCropArea: 1, autoCropArea: 0.9,
background: false, background: true,
responsive: true,
movable: true,
zoomable: true,
});
console.log("✅ Cropper initialized");
}); });
}; };
}, }
// //
async uploadCroppedImage() { async uploadCroppedImage() {