changed logic in ocr for cropping

This commit is contained in:
dhanabalan
2025-10-24 17:09:44 +05:30
parent d2b68c8c63
commit bb7e5cc12d

View File

@@ -398,7 +398,7 @@ function cameraCapture() {
// },
async capturePhoto() {
async capturePhoto() {
const video = this.$refs.video;
const canvas = this.$refs.canvas;
const ctx = canvas.getContext('2d');
@@ -408,19 +408,26 @@ function cameraCapture() {
ctx.drawImage(video, 0, 0);
const snapshot = this.$refs.snapshot;
snapshot.src = canvas.toDataURL('image/png');
snapshot.classList.remove('hidden');
video.classList.add('hidden');
this.photoTaken = true;
this.stopCamera();
// ✅ Show cropped image view first
snapshot.onload = () => {
snapshot.classList.remove('hidden');
video.classList.add('hidden');
this.photoTaken = true;
this.stopCamera();
// ✅ Enable Cropper now
this.cropper = new Cropper(snapshot, {
aspectRatio: NaN,
viewMode: 1,
dragMode: 'crop'
});
// ✅ Now start Cropper (only after image becomes visible)
this.cropper?.destroy();
this.cropper = new Cropper(snapshot, {
aspectRatio: NaN, // free crop
dragMode: 'crop',
viewMode: 1,
autoCropArea: 0.8,
background: false,
});
};
},
//
@@ -431,7 +438,7 @@ function cameraCapture() {
return;
}
const croppedCanvas = this.cropper.getCroppedCanvas();
const croppedCanvas = this.cropper.getCroppedCanvas({ imageSmoothingEnabled: true });
croppedCanvas.toBlob(async blob => {