thiagoalessio / tesseract-ocr-for-php

A wrapper to work with Tesseract OCR inside PHP.
https://packagist.org/packages/thiagoalessio/tesseract_ocr
MIT License
2.86k stars 551 forks source link

When using imageData, checkTesseractPresence is not called #210

Closed samwilson closed 3 years ago

samwilson commented 3 years ago

Expected behavior

The run() method should throw the following error for an unknown executable even when using imageData() to set the image.

The command "foobar" was not found.

Actual behavior

The actual error that is shown is:

Error! Reading image data from stdin is not available this tesseract version Required version is 3.03-rc1, actual version is 1:

Generated command: "foobar" "" "/tmp/ocrKnFVot"

This is because FriendlyErrors::checkTesseractVersion() is called in imageData(), which happens before FriendlyErrors::checkTesseractPresence() is called in run().

Steps to reproduce the behavior

$ocr = new TesseractOCR();
$ocr->executable('foobar');
$ocr->imageData($data, $size);
$ocr->run();

A workaround is to do this:

$ocr = new TesseractOCR();
$ocr->executable('foobar');
FriendlyErrors::checkTesseractPresence($ocr->command->executable);
$ocr->imageData($data, $size);
$ocr->run();

Environment

thiagoalessio commented 3 years ago

@samwilson thank you so much for reporting it. What you found is also true for other methods that also check tesseractVersion before checking the executable's presence. I'll let you know as soon as I push the fix. Thanks again.

thiagoalessio commented 3 years ago

@samwilson fix should be available in version 2.11.2. Feel free to re-open this issue in case the fix isn't complete, and thanks again for taking the time to report this bug!

samwilson commented 3 years ago

Terrific, thank you for the speedy response! :-)