added logic in ocr for cropping

This commit is contained in:
dhanabalan
2025-10-24 17:45:35 +05:30
parent e1bc838737
commit 6fe4289567

View File

@@ -340,33 +340,37 @@ function cameraCapture() {
const snapshot = this.$refs.snapshot;
snapshot.src = canvas.toDataURL('image/png');
// ✅ Wait until image is loaded
snapshot.onload = () => {
// ✅ Make snapshot visible for Cropper
snapshot.classList.remove('hidden');
video.classList.add('hidden');
this.stopCamera();
// ✅ Alpine reactive update inside nextTick
this.$nextTick(() => {
this.photoTaken = true;
// Destroy old cropper if exists
// Destroy old cropper if exists
if (this.cropper) this.cropper.destroy();
// Initialize cropper
// ✅ Use requestAnimationFrame to ensure browser painted the image
requestAnimationFrame(() => {
this.cropper = new Cropper(snapshot, {
aspectRatio: NaN,
dragMode: 'crop',
viewMode: 1,
autoCropArea: 0.9,
autoCropArea: 0.8,
background: true,
responsive: true,
movable: true,
zoomable: true,
responsive: true,
});
console.log("✅ Cropper initialized");
// ✅ Update Alpine reactivity so buttons show
this.$nextTick(() => {
this.photoTaken = true;
});
this.stopCamera(); // stop camera after Cropper starts
});
};