-1

TesseractOCR PHP, how do I catch the error if the image returns no text?

( ! ) Fatal error: Uncaught thiagoalessio\TesseractOCR\UnsuccessfulCommandException: Error!

1 Answers1

0

This is what I came up with, it's all I need to catch the error:

<?php
require_once "vendor/autoload.php";

use thiagoalessio\TesseractOCR\TesseractOCR;

try{
    $parse = 
        (new TesseractOCR('path-to-image/blank.gif'))
        ->executable('C:\Program Files\Tesseract-OCR\tesseract.exe')
        ->run();
    echo $parse;
} catch(Exception $errors) {
    echo 'Message: ' .$errors->getMessage();
}
ᴄʀᴏᴢᴇᴛ
  • 2,939
  • 26
  • 44