feat: add error handling to OCR image processing function

This commit is contained in:
n4ze3m 2025-02-08 23:07:57 +05:30
parent ef51cf85ff
commit 4438613c2d

View File

@ -1,6 +1,7 @@
import { createWorker } from "tesseract.js"
export async function processImageForOCR(imageData: string): Promise<string> {
try {
const isOCROffline = import.meta.env.BROWSER === "edge"
const worker = await createWorker(!isOCROffline ? "eng-fast" : "eng", undefined, {
workerPath: "/ocr/worker.min.js",
@ -15,4 +16,8 @@ export async function processImageForOCR(imageData: string): Promise<string> {
await worker.terminate()
return result.data.text
} catch (error) {
console.error("Error processing image for OCR:", error)
return ""
}
}