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 Loading

  1. core core Public

    Core modules and interfaces.

    PHP 5

  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 1 1

Repositories

Showing 6 of 6 repositories
  • ocr-space-engine Public

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

    php-ocr/ocr-space-engine’s past year of commit activity
    PHP 1 1 0 0 Updated Nov 13, 2021
  • http Public

    Modules and interfaces for HTTP engines.

    php-ocr/http’s past year of commit activity
    PHP 0 0 0 0 Updated Nov 13, 2021
  • core Public

    Core modules and interfaces.

    php-ocr/core’s past year of commit activity
    PHP 5 0 0 0 Updated Nov 13, 2021
  • .github Public
    php-ocr/.github’s past year of commit activity
    0 0 0 0 Updated Nov 13, 2021
  • docker Public
    php-ocr/docker’s past year of commit activity
    0 0 0 0 Updated Nov 13, 2021
  • php-ocr/pipelines’s past year of commit activity
    PHP 0 0 0 0 Updated Nov 6, 2021

Top languages

PHP

Most used topics

Loading…