### Install Tesseract OCR on Windows via Chocolatey Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Provides instructions for Windows users to install Tesseract OCR using Chocolatey. It recommends the Capture2Text package for a quick setup, noting potential issues with recent versions. ```bash choco install capture2text --version 3.9 ``` -------------------------------- ### Install Tesseract OCR for PHP with Composer Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Installs the Tesseract OCR PHP library using Composer. This is the recommended method for managing dependencies in PHP projects. ```bash $ composer require thiagoalessio/tesseract_ocr ``` -------------------------------- ### Install Tesseract OCR on macOS with MacPorts Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Instructions for macOS users to install Tesseract OCR and language support using MacPorts. It shows how to install specific language packs. ```bash sudo port install tesseract- ``` -------------------------------- ### Install Tesseract OCR and all languages on macOS with Homebrew Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Instructions for macOS users to install Tesseract OCR and all available language packs using Homebrew. This is a convenient way to ensure support for multiple languages. ```bash brew install tesseract tesseract-lang ``` -------------------------------- ### Tesseract OCR API Documentation Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Provides documentation for the TesseractOCR class methods, covering image processing, language configuration, executable path, and version retrieval. It details parameters, return values, and usage examples for each method. ```APIDOC TesseractOCR Class Methods: run(int $timeout = null) Executes a tesseract command. Optionally accepts a timeout in seconds to prevent stalled processes. Parameters: $timeout: Optional. The timeout in seconds for the tesseract process. Returns: The OCR result string. Examples: $ocr = new TesseractOCR(); $ocr->run(); $ocr = new TesseractOCR(); $timeout = 500; $ocr->run($timeout); image(string $path) Defines the path of the image file to be recognized by tesseract. Parameters: $path: The file path to the image. Examples: $ocr = new TesseractOCR(); $ocr->image('/path/to/image.png'); $ocr->run(); imageData(string $data, int $size) Sets the image data from a string, along with its size. Useful for images loaded in memory. Parameters: $data: The image data as a string. $size: The size of the image data in bytes. Examples: // Using Imagick $data = $img->getImageBlob(); $size = $img->getImageLength(); $ocr->imageData($data, $size); // Using GD ob_start(); imagepng($img, null, 0); $size = ob_get_length(); $data = ob_get_clean(); $ocr->imageData($data, $size); executable(string $path) Defines a custom location for the tesseract executable if it's not in the system's PATH. Parameters: $path: The absolute path to the tesseract executable. Examples: echo (new TesseractOCR('img.png')) ->executable('/path/to/tesseract') ->run(); version() Returns the current version of the installed Tesseract OCR. Returns: The tesseract version string. Examples: echo (new TesseractOCR())->version(); availableLanguages() Returns a list of languages and scripts supported by the installed Tesseract OCR. Returns: An array of language codes. Examples: foreach((new TesseractOCR())->availableLanguages() as $lang) echo $lang; More info: https://github.com/tesseract-ocr/tesseract/blob/master/doc/tesseract.1.asc#languages-and-scripts tessdataDir(string $path) Specifies a custom directory for the tessdata files, which contain language models. Parameters: $path: The path to the tessdata directory. Examples: echo (new TesseractOCR('img.png')) ->tessdataDir('/path') ->run(); ``` -------------------------------- ### Configure Tesseract OCR with Dynamic Methods Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Provides a dynamic way to set Tesseract configuration parameters by mapping method names to parameter names. For example, `->configVar('value')` would set the `config_var` parameter. This offers a more fluent interface for custom configurations. ```php echo (new TesseractOCR('img.png')) ->configVar('value') ->otherConfigVar('other value') ->run(); ``` -------------------------------- ### Specify Page Segmentation Method (PSM) in Tesseract OCR PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Sets the Page Segmentation Method (PSM) to guide Tesseract on how to interpret the image. This influences how text blocks, lines, and words are detected. It takes an integer representing the PSM mode. ```php echo (new TesseractOCR('img.png')) ->psm(6) ->run(); ``` -------------------------------- ### Basic OCR Recognition in PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Demonstrates the basic usage of the TesseractOCR library to perform OCR on an image file. It initializes the class with an image path and runs the recognition process. ```php use thiagoalessio\TesseractOCR\TesseractOCR; echo (new TesseractOCR('text.png')) ->run(); ``` -------------------------------- ### Use TXT Configuration in Tesseract OCR PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md A shortcut method to apply the 'txt' configuration file, which ensures the output is in plain text format. This is the default behavior but can be explicitly set. ```php echo (new TesseractOCR('img.png')) ->txt() ->run(); ``` -------------------------------- ### Configure Tesseract OCR with Custom Parameters Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Allows setting any Tesseract configuration parameter not directly exposed by a dedicated method. This provides flexibility to use advanced or less common Tesseract options. It takes a parameter name and its value as arguments. ```php echo (new TesseractOCR('img.png')) ->config('config_var', 'value') ->config('other_config_var', 'other value') ->run(); ``` -------------------------------- ### Specify Configuration File for Tesseract OCR PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Allows specifying a Tesseract configuration file, either a custom path or a predefined one like 'hocr'. This method is used to apply specific Tesseract settings. It takes a configuration name or path as a string. ```php echo (new TesseractOCR('img.png')) ->configFile('hocr') ->run(); ``` -------------------------------- ### Set User Words File in Tesseract OCR PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Specifies the location of a plain text file containing words to be recognized as normal dictionary words. This is useful for technical terminology or jargon. It takes a file path as input. ```bash cat /path/to/user-words.txt foo bar ``` ```php echo (new TesseractOCR('img.png')) ->userWords('/path/to/user-words.txt') ->run(); ``` -------------------------------- ### Use Digits Configuration in Tesseract OCR PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md A shortcut method to apply the 'digits' configuration file, which is useful for OCR tasks focused solely on numerical digits. It simplifies the process of setting this common configuration. ```php echo (new TesseractOCR('img.png')) ->digits() ->run(); ``` -------------------------------- ### Set User Patterns File in Tesseract OCR PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Specifies the location of a file containing known patterns to improve recognition accuracy. Patterns can include regular expressions or specific formats. It accepts a file path as an argument. ```bash cat /path/to/user-patterns.txt 1-\d\d\d-GOOG-441 www.\\*.com ``` ```php echo (new TesseractOCR('img.png')) ->userPatterns('/path/to/user-patterns.txt') ->run(); ``` -------------------------------- ### OCR Recognition with Multiple Languages in PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Illustrates how to enable OCR for multiple languages simultaneously by passing them as arguments to the `lang()` method. This is essential for images containing mixed languages. ```php use thiagoalessio\TesseractOCR\TesseractOCR; echo (new TesseractOCR('mixed-languages.png')) ->lang('eng', 'jpn', 'spa') ->run(); ``` -------------------------------- ### Use PDF Configuration in Tesseract OCR PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md A shortcut method to apply the 'pdf' configuration file, which generates a searchable PDF document from the OCR output. This is useful for creating text-searchable documents from scanned images. ```php echo (new TesseractOCR('img.png')) ->pdf() ->run(); ``` -------------------------------- ### Use Quiet Configuration in Tesseract OCR PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md A shortcut method to apply the 'quiet' configuration file. This configuration typically suppresses verbose output from Tesseract, providing cleaner results. ```php echo (new TesseractOCR('img.png')) ->quiet() ->run(); ``` -------------------------------- ### Define Temporary Directory for Tesseract OCR PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Specifies a custom directory for Tesseract to store temporary files generated during the OCR process. The directory must exist and be writable by the PHP process. It takes a directory path as a string. ```php echo (new TesseractOCR('img.png')) ->tempDir('./my/custom/temp/dir') ->run(); ``` -------------------------------- ### OCR Recognition with Allowed Character Set in PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Demonstrates how to restrict the character recognition to a specific set of characters using the `allowlist()` method. This is useful for improving accuracy on CAPTCHAs or specific character sets. ```php use thiagoalessio\TesseractOCR\TesseractOCR; echo (new TesseractOCR('8055.png')) ->allowlist(range('A', 'Z')) ->run(); ``` -------------------------------- ### Use HOCR Configuration in Tesseract OCR PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md A shortcut method to apply the 'hocr' configuration file, enabling the output of results in the Hierarchical OCR (HOCR) format. HOCR provides structured, semantic mark-up of text and its spatial location. ```php echo (new TesseractOCR('img.png')) ->hocr() ->run(); ``` -------------------------------- ### Use TSV Configuration in Tesseract OCR PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md A shortcut method to apply the 'tsv' configuration file, which outputs the OCR results in a Tab-Separated Values (TSV) format. This format is useful for programmatic parsing of recognized text and its properties. ```php echo (new TesseractOCR('img.png')) ->tsv() ->run(); ``` -------------------------------- ### Set Output File for Tesseract OCR PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Specifies the output file path for the OCR results. When an output file is set, the `withoutTempFiles` option is ignored, and temporary files are still written. This method is often used with `configFile` to generate specific output formats like PDF or HOCR. ```php echo (new TesseractOCR('img.png')) ->configFile('pdf') ->setOutputFile('/PATH_TO_MY_OUTPUTFILE/searchable.pdf') ->run(); ``` -------------------------------- ### OCR Recognition with a Specific Language in PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Shows how to specify a single language for OCR recognition using the `lang()` method. This is useful when dealing with images containing text in a known language other than English. ```php use thiagoalessio\TesseractOCR\TesseractOCR; echo (new TesseractOCR('german.png')) ->lang('deu') ->run(); ``` -------------------------------- ### Specify OCR Engine Mode (OEM) in Tesseract OCR PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Sets the OCR Engine Mode (OEM) for Tesseract. This determines which OCR engine (e.g., legacy, neural nets) is used. It accepts an integer corresponding to the desired OEM mode. ```php echo (new TesseractOCR('img.png')) ->oem(2) ->run(); ``` -------------------------------- ### Set Character Allowlist in Tesseract OCR PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md A shortcut to configure Tesseract to only recognize a specific set of characters. This is useful for filtering out unwanted characters or focusing on a known character set. It accepts characters or ranges as arguments. ```php echo (new TesseractOCR('img.png')) ->allowlist(range('a', 'z'), range(0, 9), '-_@') ->run(); ``` -------------------------------- ### Define Languages for Tesseract OCR PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Defines one or more languages to be used during the OCR process. Multiple languages can be specified for combined recognition, such as Chinese simplified and traditional. Accepts language codes as string arguments. ```php echo (new TesseractOCR('img.png')) ->lang('chi_sim', 'chi_tra') ->run(); ``` -------------------------------- ### Disable Temporary Files in Tesseract OCR PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Instructs Tesseract to output recognized text directly to standard output without writing to temporary files. This can be useful for streamlining processes or when temporary file storage is restricted. This option is ignored if `setOutputFile` is used. ```php echo (new TesseractOCR('img.png')) ->withoutTempFiles() ->run(); ``` -------------------------------- ### Set Image DPI in Tesseract OCR PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Specifies the image DPI (dots per inch) if it's not embedded in the image metadata. Correct DPI can significantly improve recognition accuracy. It takes an integer DPI value. ```php echo (new TesseractOCR('img.png')) ->dpi(300) ->run(); ``` -------------------------------- ### Limit Tesseract OCR Threads in PHP Source: https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/main/README.md Sets the maximum number of threads that Tesseract is allowed to use during processing. This can be beneficial for managing system resources or resolving specific concurrency issues. It takes the maximum thread count as an integer argument. ```php echo (new TesseractOCR('img.png')) ->threadLimit(1) ->run(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.