From 0c3e031842caccaacc6ffbcfa9dab38f09fe125c Mon Sep 17 00:00:00 2001 From: Vladimir Khramtsov Date: Fri, 15 Jan 2021 15:46:47 +0300 Subject: [PATCH] Improve code and add some integrations --- .gitignore | 1 + .travis.yml | 5 ++++- README.md | 27 +++++++++++------------ build.xml | 5 ++++- phpunit.xml.dist | 32 +++++++++++++++------------- src/Bicycle/Tesseract/Bridge/CLI.php | 3 ++- tests/prepareData.sh | 4 ++-- 7 files changed, 42 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index ee57009..d2574b7 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ ###> Utility files ### /tests/tmp/ +/clover.xml ###< Utility files ### diff --git a/.travis.yml b/.travis.yml index e81c46a..1407f28 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,5 +44,8 @@ script: - php vendor/bin/psalm --show-info=true - php vendor/bin/phpcpd src - php vendor/bin/phpcpd tests - - php vendor/bin/phpunit + - php -d=xdebug.mode=coverage vendor/bin/phpunit - composer outdated -D + +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/README.md b/README.md index a1eecb7..3d35805 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,15 @@ -A wrapper to work with Tesseract OCR inside PHP via CLI and/or FFI interfaces. [![Build Status](https://travis-ci.org/vkhramtsov/tesseract-bridge.svg?branch=master)](https://travis-ci.org/vkhramtsov/tesseract-bridge) +A wrapper to work with Tesseract OCR inside PHP via CLI and/or FFI interfaces. -:bangbang: **Tested only on FreeBSD and Debian and Ubuntu platforms with [Tesseract OCR][] version 3 and 4 (see build logs).** +[![Build Status](https://travis-ci.org/vkhramtsov/tesseract-bridge.svg?branch=master)](https://travis-ci.org/vkhramtsov/tesseract-bridge) +[![Codacy Badge](https://app.codacy.com/project/badge/Grade/58a3278711f649dd80b97c6871189d02)](https://www.codacy.com/gh/vkhramtsov/tesseract-bridge/dashboard?utm_source=github.com&utm_medium=referral&utm_content=vkhramtsov/tesseract-bridge&utm_campaign=Badge_Grade) +[![codecov](https://codecov.io/gh/vkhramtsov/tesseract-bridge/branch/master/graph/badge.svg?token=U056TFE2OO)](https://codecov.io/gh/vkhramtsov/tesseract-bridge) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/vkhramtsov/tesseract-bridge/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/vkhramtsov/tesseract-bridge/?branch=master) + +:bangbang: **Tested only on FreeBSD and Debian and Ubuntu platforms with [Tesseract OCR](https://github.com/tesseract-ocr/tesseract) version 3 and 4 (see build logs).** ## Installation -Via [Composer][]: +Via [Composer](https://getcomposer.org/): $ composer require bicycle/tesseract-bridge @@ -64,20 +69,12 @@ Via [Composer][]: You can contribute to this project by: -* Opening an [Issue][] if you found a bug or wish to propose a new feature; -* Opening [PR][] if you want to improve/create/fix something +- Opening an [Issue](../../issues) if you found a bug or wish to propose a new feature; +- Opening [PR](../../pulls) if you want to improve/create/fix something ## Additional -Please check our [FAQ][] +Please check our [FAQ](./Resources/doc/faq.rst) ## License -tesseract-ocr-for-php is released under the [MIT License][]. - - -[Tesseract OCR]: https://github.com/tesseract-ocr/tesseract -[Composer]: https://getcomposer.org/ -[Issue]: ../../issues -[PR]: ../../pulls -[FAQ]: ./Resources/doc/faq.rst -[MIT License]: ./LICENSE +tesseract-bridge is released under the [MIT License](./LICENSE). diff --git a/build.xml b/build.xml index 6e26cb6..2103509 100644 --- a/build.xml +++ b/build.xml @@ -87,7 +87,10 @@ - + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ceb9559..89492f1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,17 +1,19 @@ - - - - - - - - ./tests/Bicycle/Tesseract/*/ - - - + + + + + + + ./tests/Bicycle/Tesseract/*/ + + + + + src + + + + + diff --git a/src/Bicycle/Tesseract/Bridge/CLI.php b/src/Bicycle/Tesseract/Bridge/CLI.php index 6420eca..22cdab6 100644 --- a/src/Bicycle/Tesseract/Bridge/CLI.php +++ b/src/Bicycle/Tesseract/Bridge/CLI.php @@ -86,6 +86,8 @@ public function recognizeFromFile(string $filename, array $languages = []): stri */ str_replace([DIRECTORY_SEPARATOR], '_', base64_encode(random_bytes(5))) ); + + // Adding .txt because tesseract automatically add .txt to output files $realTmpOutFile = $tmpOutFile . '.txt'; $this->executeCommand( [ @@ -95,7 +97,6 @@ public function recognizeFromFile(string $filename, array $languages = []): stri ] ); - // Adding .txt because tesseract automatically add .txt to output files $recognizedText = rtrim(file_get_contents($realTmpOutFile), "\f"); unlink($realTmpOutFile); diff --git a/tests/prepareData.sh b/tests/prepareData.sh index f6e4053..5fefaf5 100755 --- a/tests/prepareData.sh +++ b/tests/prepareData.sh @@ -1,9 +1,9 @@ #!/bin/sh -xe -currentDir="$(dirname $(realpath $0))" +currentDir="$(dirname $(realpath "$0"))" tmpDir="$currentDir/tmp"; -mkdir -p $tmpDir +mkdir -p "$tmpDir" tesseract --version 2>&1 | head -n 1 | sed 's/tesseract //' > "$tmpDir/version.txt" tesseract --list-langs 2>&1 | tail -n+2 > "$tmpDir/langs.txt" tesseract "$currentDir/data/image/eurotext.png" "$tmpDir/eurotext-eng" -l eng