diff --git a/Ai/Ocr/Tesseract/TesseractOcr.php b/Ai/Ocr/Tesseract/TesseractOcr.php index 3954bbcf0..959ef09a6 100644 --- a/Ai/Ocr/Tesseract/TesseractOcr.php +++ b/Ai/Ocr/Tesseract/TesseractOcr.php @@ -102,14 +102,22 @@ final class TesseractOcr . ' -l ' . \implode('+', $languages) ); - $parsed = \file_get_contents($temp . '.txt'); + $filepath = \is_file($temp . '.txt') + ? $temp . '.txt' + : $temp; + + if (!\is_file($filepath)) { + return ''; + } + + $parsed = \file_get_contents($filepath); if ($parsed === false) { return ''; } // @todo: auto flip image if x% of text are garbage words? - \unlink($temp); + \unlink($filepath); return \trim($parsed); } diff --git a/tests/Ai/Ocr/Tesseract/TesseractOcrTest.php b/tests/Ai/Ocr/Tesseract/TesseractOcrTest.php index b4a15c690..3eb2381a9 100644 --- a/tests/Ai/Ocr/Tesseract/TesseractOcrTest.php +++ b/tests/Ai/Ocr/Tesseract/TesseractOcrTest.php @@ -24,6 +24,18 @@ use phpOMS\Image\Thresholding; */ final class TesseractOcrTest extends \PHPUnit\Framework\TestCase { + /** + * {@inheritdoc} + */ + protected function setUp() : void + { + if (!\is_file('/usr/bin/tesseract')) { + $this->markTestSkipped( + 'Couldn\'t find tesseract' + ); + } + } + private function outputTest(string $name, float $m1, float $m2) : void { if (false) {