Skip to content

Commit

Permalink
Improve code and add some integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
vkhramtsov committed Jan 15, 2021
1 parent 8808e15 commit 0c3e031
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@

###> Utility files ###
/tests/tmp/
/clover.xml
###< Utility files ###
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
27 changes: 12 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -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&amp;utm_medium=referral&amp;utm_content=vkhramtsov/tesseract-bridge&amp;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

Expand Down Expand Up @@ -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).
5 changes: 4 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@

<target name="phpunit" description="Run tests">
<!-- Using exec here because phing cannot find phpunit -->
<exec executable="${project-vendor-bin-dir}/phpunit" dir="." checkReturn="false" outputProperty="phpunit-results" returnProperty="phpunit-return" />
<exec executable="${php-bin}" dir="." checkReturn="false" outputProperty="phpunit-results" returnProperty="phpunit-return" >
<arg value="-d=xdebug.mode=coverage" />
<arg value="${project-vendor-bin-dir}/phpunit" />
</exec>
<echo message="${phpunit-results}" />
<if>
<istrue value="${phpunit-return}" />
Expand Down
32 changes: 17 additions & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.4/phpunit.xsd"
backupGlobals="false"
cacheResult="false"
colors="true">
<php>
<ini name="error_reporting" value="-1" />
</php>

<testsuites>
<testsuite name="Main">
<directory>./tests/Bicycle/Tesseract/*/</directory>
</testsuite>
</testsuites>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" cacheResult="false" colors="true">
<php>
<ini name="error_reporting" value="-1"/>
</php>
<testsuites>
<testsuite name="Main">
<directory>./tests/Bicycle/Tesseract/*/</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="clover.xml"/>
</report>
</coverage>
</phpunit>
3 changes: 2 additions & 1 deletion src/Bicycle/Tesseract/Bridge/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/prepareData.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 0c3e031

Please sign in to comment.