PHPackages                             ikerst/tesseract\_ocr - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ikerst/tesseract\_ocr

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ikerst/tesseract\_ocr
=====================

A wrapper to work with Tesseract OCR inside PHP.

0131PHP

Since Apr 3Pushed 6y ago1 watchersCompare

[ Source](https://github.com/IkerST/TesseractOCR)[ Packagist](https://packagist.org/packages/ikerst/tesseract_ocr)[ RSS](/packages/ikerst-tesseract-ocr/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Tesseract OCR for PHP
=====================

[](#tesseract-ocr-for-php)

A wrapper to work with Tesseract OCR inside PHP.

Installation
------------

[](#installation)

Via \[Composer\]\[\]:

```
$ composer require IkerST/tesseract_ocr

```

‼️ **This library depends on \[Tesseract OCR\]\[\], version *3.02* or later.**

### Note for Windows users

[](#note-for-windows-users)

There are \[many ways\]\[tesseract\_installation\_on\_windows\] to install \[Tesseract OCR\]\[\] on your system, but if you just want something quick to get up and running, I recommend installing the \[Capture2Text\]\[\] package with \[Chocolatey\]\[\].

```
choco install capture2text --version 3.9

```

⚠️ Recent versions of Capture2Text stopped shipping the `tesseract` binary.

### Note for macOS users

[](#note-for-macos-users)

With \[MacPorts\]\[\] you can install support for individual languages, like so:

```
	sudo port install tesseract-
```

But that is not possible with \[Homebrew\]\[\]. It comes only with **English** support by default, so if you intend to use it for other language, the quickest solution is to install them all:

```
brew install tesseract --with-all-languages
```

Usage
-----

[](#usage)

### Basic usage

[](#basic-usage)

```
use IkerST\TesseractOCR\TesseractOCR;
echo (new TesseractOCR('text.png'))
    ->run();
```

### Other languages

[](#other-languages)

```
use IkerST\TesseractOCR\TesseractOCR;
echo (new TesseractOCR('german.png'))
    ->lang('deu')
    ->run();
```

### Multiple languages

[](#multiple-languages)

```
use IkerST\TesseractOCR\TesseractOCR;
echo (new TesseractOCR('mixed-languages.png'))
    ->lang('eng', 'jpn', 'spa')
    ->run();
```

### Inducing recognition

[](#inducing-recognition)

```
use IkerST\TesseractOCR\TesseractOCR;
echo (new TesseractOCR('8055.png'))
    ->whitelist(range('A', 'Z'))
    ->run();
```

API
---

[](#api)

### image

[](#image)

Define the path of an image to be recognized by `tesseract`.

```
$ocr = new TesseractOCR();
$ocr->image('/path/to/image.png');
$ocr->run();
```

### imageData

[](#imagedata)

Set the image to be recognized by `tesseract` from a string, with its size. This can be useful when dealing with files that are already loaded in memory. You can easily retrieve the image data and size of an image object :

```
//Using Imagick
$data = $img->getImageBlob();
$size = $img->getImageLength();
//Using GD
ob_start();
// Note that you can use any format supported by tesseract
imagepng($img, null, 0);
$size = ob_get_length();
$data = ob_get_clean();

$ocr = new TesseractOCR();
$ocr->imageData($data, $size);
$ocr->run();
```

### executable

[](#executable)

Define a custom location of the `tesseract` executable, if by any reason it is not present in the `$PATH`.

```
echo (new TesseractOCR('img.png'))
    ->executable('/path/to/tesseract')
    ->run();
```

### version

[](#version)

Returns the current version of `tesseract`.

```
echo (new TesseractOCR())->version();
```

### availableLanguages

[](#availablelanguages)

Returns a list of available languages/scripts.

```
foreach((new TesseractOCR())->availableLanguages() as $lang) echo $lang;
```

**More info:**

### tessdataDir

[](#tessdatadir)

Specify a custom location for the tessdata directory.

```
echo (new TesseractOCR('img.png'))
    ->tessdataDir('/path')
    ->run();
```

### userWords

[](#userwords)

Specify the location of user words file.

This is a plain text file containing a list of words that you want to be considered as a normal dictionary words by `tesseract`.

Useful when dealing with contents that contain technical terminology, jargon, etc.

```
$ cat /path/to/user-words.txt
foo
bar

```

```
echo (new TesseractOCR('img.png'))
    ->userWords('/path/to/user-words.txt')
    ->run();
```

### userPatterns

[](#userpatterns)

Specify the location of user patterns file.

If the contents you are dealing with have known patterns, this option can help a lot tesseract's recognition accuracy.

```
$ cat /path/to/user-patterns.txt'
1-\d\d\d-GOOG-441
www.\n\\\*.com

```

```
echo (new TesseractOCR('img.png'))
    ->userPatterns('/path/to/user-patterns.txt')
    ->run();
```

### lang

[](#lang)

Define one or more languages to be used during the recognition. A complete list of available languages can be found at:

Use the combination `->lang('chi_sim', 'chi_tra')`for proper recognition of Chinese.

```
 echo (new TesseractOCR('img.png'))
     ->lang('lang1', 'lang2', 'lang3')
     ->run();
```

### psm

[](#psm)

Specify the Page Segmentation Method, which instructs `tesseract` how to interpret the given image.

**More info:**

```
echo (new TesseractOCR('img.png'))
    ->psm(6)
    ->run();
```

### oem

[](#oem)

Specify the OCR Engine Mode. (see `tesseract --help-oem`)

```
echo (new TesseractOCR('img.png'))
    ->oem(2)
    ->run();
```

### whitelist

[](#whitelist)

This is a shortcut for `->config('tessedit_char_whitelist', 'abcdef....')`.

```
echo (new TesseractOCR('img.png'))
    ->whitelist(range('a', 'z'), range(0, 9), '-_@')
    ->run();
```

### configFile

[](#configfile)

Specify a config file to be used. It can either be the path to your own config file or the name of one of the predefined config files:

```
echo (new TesseractOCR('img.png'))
    ->configFile('hocr')
    ->run();
```

### setOutputFile

[](#setoutputfile)

Specify an Outputfile to be used. Be aware: If you set an outputfile then the option `withoutTempFiles` is ignored. Tempfiles are written (and deleted) even if `withoutTempFiles = true`.

In combination with `configFile` you are able to get the `hocr`, `tsv` or `pdf` files.

```
echo (new TesseractOCR('img.png'))
    ->configFile('pdf')
    ->setOutputFile('/PATH_TO_MY_OUTPUTFILE/searchable.pdf');
    ->run();
```

### digits

[](#digits)

Shortcut for `->configFile('digits')`.

```
echo (new TesseractOCR('img.png'))
    ->digits()
    ->run();
```

### hocr

[](#hocr)

Shortcut for `->configFile('hocr')`.

```
echo (new TesseractOCR('img.png'))
    ->hocr()
    ->run();
```

### pdf

[](#pdf)

Shortcut for `->configFile('pdf')`.

```
echo (new TesseractOCR('img.png'))
    ->pdf()
    ->run();
```

### quiet

[](#quiet)

Shortcut for `->configFile('quiet')`.

```
echo (new TesseractOCR('img.png'))
    ->quiet()
    ->run();
```

### tsv

[](#tsv)

Shortcut for `->configFile('tsv')`.

```
echo (new TesseractOCR('img.png'))
    ->tsv()
    ->run();
```

### txt

[](#txt)

Shortcut for `->configFile('txt')`.

```
echo (new TesseractOCR('img.png'))
    ->txt()
    ->run();
```

### tempDir

[](#tempdir)

Define a custom directory to store temporary files generated by tesseract. Make sure the directory actually exists and the user running `php` is allowed to write in there.

```
echo (new TesseractOCR('img.png'))
    ->tempDir('./my/custom/temp/dir')
    ->run();
```

### withoutTempFiles

[](#withouttempfiles)

Specify that `tesseract` should output the recognized text without writing to temporary files. The data is gathered from the standard output of `tesseract` instead.

```
echo (new TesseractOCR('img.png'))
    ->withoutTempFiles()
    ->run();
```

### Other options

[](#other-options)

Any configuration option offered by Tesseract can be used like that:

```
echo (new TesseractOCR('img.png'))
    ->config('config_var', 'value')
    ->config('other_config_var', 'other value')
    ->run();
```

Or like that:

```
echo (new TesseractOCR('img.png'))
    ->configVar('value')
    ->otherConfigVar('other value')
    ->run();
```

**More info:**

### Thread-limit

[](#thread-limit)

Sometimes, it may be useful to limit the number of threads that tesseract is allowed to use (e.g. in [this case](https://github.com/tesseract-ocr/tesseract/issues/898)). Set the maxmium number of threads as param for the `run` function:

```
echo (new TesseractOCR('img.png'))
    ->threadLimit(1)
    ->run();
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/35041658?v=4)[Iker Sandí Trejo](/maintainers/IkerST)[@IkerST](https://github.com/IkerST)

---

Top Contributors

[![IkerST](https://avatars.githubusercontent.com/u/35041658?v=4)](https://github.com/IkerST "IkerST (8 commits)")

### Embed Badge

![Health badge](/badges/ikerst-tesseract-ocr/health.svg)

```
[![Health](https://phpackages.com/badges/ikerst-tesseract-ocr/health.svg)](https://phpackages.com/packages/ikerst-tesseract-ocr)
```

###  Alternatives

[cknow/laravel-money

Laravel Money

1.0k4.3M22](/packages/cknow-laravel-money)[mnsami/composer-custom-directory-installer

A composer plugin, to help install packages of different types in custom paths.

1395.0M52](/packages/mnsami-composer-custom-directory-installer)[damienharper/adf-tools

Atlassian Document Format PHP Tools

141.4M2](/packages/damienharper-adf-tools)[julien731/wp-dismissible-notices-handler

A simple library to handle Ajax-dismissible admin notices for WordPress

456.2k1](/packages/julien731-wp-dismissible-notices-handler)[plunkettscott/laravel-otel

OpenTelemetry for Laravel

294.6k](/packages/plunkettscott-laravel-otel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
