feat: add error handling to OCR image processing function
This commit is contained in:
parent
ef51cf85ff
commit
4438613c2d
@ -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 ""
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user