Added one more repsonse for empty invalid image

This commit is contained in:
dhanabalan
2025-10-23 15:57:28 +05:30
parent 9aff6dfb67
commit a983d116cf

View File

@@ -52,6 +52,13 @@ use thiagoalessio\TesseractOCR\TesseractOCR;
->config('tessedit_char_whitelist', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')
->run();
$text = trim($text); // remove whitespace
if (empty($text)) {
// No text found
return response()->json(['success' => true, 'text' => 'Text not found']);
}
//return response()->json(['success' => true, 'text' => $text]);
$lines = preg_split('/\r\n|\r|\n/', $text);
$serials = array_filter(array_map('trim', $lines), fn($line) => preg_match('/^[A-Za-z0-9]+$/', $line));