1. Go to this page and download the library: Download psagnataf/tesseract_ocr library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
psagnataf / tesseract_ocr example snippets
use thiagoalessio\TesseractOCR\TesseractOCR;
echo (new TesseractOCR('text.png'))
->run();
use thiagoalessio\TesseractOCR\TesseractOCR;
echo (new TesseractOCR('german.png'))
->lang('deu')
->run();
use thiagoalessio\TesseractOCR\TesseractOCR;
echo (new TesseractOCR('mixed-languages.png'))
->lang('eng', 'jpn', 'spa')
->run();
use thiagoalessio\TesseractOCR\TesseractOCR;
echo (new TesseractOCR('8055.png'))
->allowlist(range('A', 'Z'))
->run();
$ocr = new TesseractOCR();
$ocr->image('/path/to/image.png');
$ocr->run();
//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();
echo (new TesseractOCR('img.png'))
->executable('/path/to/tesseract')
->run();
echo (new TesseractOCR())->version();
foreach((new TesseractOCR())->availableLanguages() as $lang) echo $lang;
echo (new TesseractOCR('img.png'))
->tessdataDir('/path')
->run();
echo (new TesseractOCR('img.png'))
->userWords('/path/to/user-words.txt')
->run();
echo (new TesseractOCR('img.png'))
->userPatterns('/path/to/user-patterns.txt')
->run();
echo (new TesseractOCR('img.png'))
->lang('lang1', 'lang2', 'lang3')
->run();
echo (new TesseractOCR('img.png'))
->psm(6)
->run();
echo (new TesseractOCR('img.png'))
->oem(2)
->run();
echo (new TesseractOCR('img.png'))
->dpi(300)
->run();
echo (new TesseractOCR('img.png'))
->allowlist(range('a', 'z'), range(0, 9), '-_@')
->run();
echo (new TesseractOCR('img.png'))
->configFile('hocr')
->run();
echo (new TesseractOCR('img.png'))
->configFile('pdf')
->setOutputFile('/PATH_TO_MY_OUTPUTFILE/searchable.pdf');
->run();
echo (new TesseractOCR('img.png'))
->digits()
->run();
echo (new TesseractOCR('img.png'))
->hocr()
->run();
echo (new TesseractOCR('img.png'))
->pdf()
->run();
echo (new TesseractOCR('img.png'))
->quiet()
->run();
echo (new TesseractOCR('img.png'))
->tsv()
->run();
echo (new TesseractOCR('img.png'))
->txt()
->run();
echo (new TesseractOCR('img.png'))
->tempDir('./my/custom/temp/dir')
->run();
echo (new TesseractOCR('img.png'))
->withoutTempFiles()
->run();
echo (new TesseractOCR('img.png'))
->config('config_var', 'value')
->config('other_config_var', 'other value')
->run();
echo (new TesseractOCR('img.png'))
->configVar('value')
->otherConfigVar('other value')
->run();
echo (new TesseractOCR('img.png'))
->threadLimit(1)
->run();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.