removed old logic
This commit is contained in:
@@ -32,25 +32,25 @@ use thiagoalessio\TesseractOCR\TesseractOCR;
|
||||
});
|
||||
|
||||
Route::post('/verify-ocr', function (Request $request) {
|
||||
$filePath = storage_path('app/private/temp/' . basename($request->path));
|
||||
$filePath = storage_path('app/private/temp/' . basename($request->path));
|
||||
|
||||
if (!file_exists($filePath)) {
|
||||
return response()->json(['success' => false, 'error' => 'File not found']);
|
||||
}
|
||||
if (!file_exists($filePath)) {
|
||||
return response()->json(['success' => false, 'error' => 'File not found']);
|
||||
}
|
||||
|
||||
$output = null;
|
||||
$return_var = null;
|
||||
try {
|
||||
// $text = (new TesseractOCR($filePath))->lang('eng')->run();
|
||||
$text = (new TesseractOCR($filePath))
|
||||
->executable('/usr/bin/tesseract')
|
||||
->env(['PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'])
|
||||
->lang('eng')
|
||||
->run();
|
||||
|
||||
// Call tesseract directly, capture stderr with 2>&1
|
||||
exec("/usr/bin/tesseract " . escapeshellarg($filePath) . " stdout -l eng 2>&1", $output, $return_var);
|
||||
|
||||
if ($return_var === 0) {
|
||||
$text = implode("\n", $output);
|
||||
return response()->json(['success' => true, 'text' => $text]);
|
||||
} else {
|
||||
return response()->json(['success' => false, 'error' => implode("\n", $output)]);
|
||||
}
|
||||
});
|
||||
return response()->json(['success' => true, 'text' => $text]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['success' => false, 'error' => $e->getMessage()]);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user