Skip to content
@php-ocr

PHP OCR

An abstraction layer for PHP over the Optical Character Recognition engines.

Optical Character Recognition for PHP

Description

This library is an abstraction layer for PHP over the Optical Character Recognition engines.

The key feature of the library is that is has no production dependencies. For example, the HTTP-related code is using only PSR interfaces and you are free to pick any implementation library and any version of that library thas fits the needs of your project.

Installation

Add the core package to your project.

composer require ocr/core

Add any of the engine packages to you project.

composer require ocr/some-engine

Usage – bird's eye view

use OCR\Engine\SomeEngine;
use OCR\Input\File;

$engine = new SomeEngine();
$image = new File('image.png');
$text = $engine->process($image);

Usage – complete example

This example uses the HTTP API provided by https://ocr.space. You will have to acquire an API key to use this engine.

Additionally install any implementation of psr/http-client, psr/http-factory and psr/http-factory. For example, guzzlehttp/guzzle and guzzlehttp/psr7.

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
use OCR\Engine\OcrSpaceEngine;
use OCR\Input\File;
use OCR\Utility\Http\Request\Multipart\GuzzleMultipartFormFactory;

$httpClient = new Client();
$requestFactory = new HttpFactory();
$formFactory = new GuzzleMultipartFormFactory();
$engine = new OcrSpaceEngine(
    $httpClient, 
    $requestFactory, 
    $formFactory, 
    'ocr-space-api-key',
);

$image = new File('input.jpeg');

$text = $engine->process($image);

Pinned

  1. core core Public

    Core modules and interfaces.

    PHP 3

  2. http http Public

    Modules and interfaces for HTTP engines.

    PHP

  3. ocr-space-engine ocr-space-engine Public

    Engine using the https://ocr.space API.

    PHP 2 1

Repositories

Showing 6 of 6 repositories

Top languages

PHP

Most used topics

Loading…