PHPackages                             lea-reift/ocr-space - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. lea-reift/ocr-space

ActiveLibrary[HTTP &amp; Networking](/categories/http)

lea-reift/ocr-space
===================

OCR Space Api wrapper library for PHP

1.0.2(1y ago)161MITPHPPHP ^8.2CI passing

Since Apr 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Lea-Reift/ocr-space)[ Packagist](https://packagist.org/packages/lea-reift/ocr-space)[ RSS](/packages/lea-reift-ocr-space/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

OCR Space API Wrapper
=====================

[](#ocr-space-api-wrapper)

A simple wrapper for [OCR Space](https://ocr.space/) API

[![MIT License](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://choosealicense.com/licenses/mit/)[![Build Status](https://github.com/Lea-Reift/ocr-space/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/Lea-Reift/ocr-space/actions?query=workflow%3A%22PHP+Composer%22)

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

[](#installation)

This wrapper requires:

- PHP ^8.2
- CURL extension enabled

You can easily install the wrapper with [Composer](https://getcomposer.org/):

```
  composer require lea-reift/ocr-space
```

Usage
-----

[](#usage)

The only required parameter for the Client is your apikey (this will be used in the requests). Then, you can chain the desired options in helper methods for the accepted request parameters.

```
require_once 'vendor/autoload.php'; // Don't forget the autoload

use LeaReift\OcrSpace\Client;

$response = (new Client('your-apikey'))
    ->fromUrl('https://dl.a9t9.com/ocr/solarcell.jpg')
    ->get();
```

API Reference
-------------

[](#api-reference)

The `Client` class provides an interface to interact with the OCR.space API, enabling optical character recognition on images from different sources. Check [OCR Space Documentation](https://ocr.space/OCRAPI#PostParameters) to dig deeper with the accepted values, but the library also counts with typed parameters methods, so use it won't be to difficult.

### Constructor

[](#constructor)

```
public function __construct(string $apiKey, string $baseUrl = "https://api.ocr.space", string $endpoint = "/parse/image")
```

Creates a new instance of the OCR Space client.

**Parameters:**

- `$apiKey` - The API key for authenticating with the OCR.space service
- `$baseUrl` - The base URL of the API (optional, defaults to "")
- `$endpoint` - The API endpoint (optional, defaults to "/parse/image")

```
use LeaReift\OcrSpace\Client;

$client = new Client('your-api-key-here');
```

### Data Input Methods

[](#data-input-methods)

#### fromUrl

[](#fromurl)

```
public function fromUrl(string $url): self
```

Sets an image URL as input for OCR processing.

**Parameters:**

- `$url` - Valid URL of the image to be processed

```
$client->fromUrl('https://example.com/image.jpg');
```

#### fromFile

[](#fromfile)

```
public function fromFile(string|CURLFile $file): self
```

Sets a local file as input for OCR processing.

**Parameters:**

- `$file` - File path as string or CURLFile instance

```
// Using string
$client->fromFile('/path/to/image.png');

// Using CURLFile
$curlFile = new CURLFile('/path/to/image.png');
$client->fromFile($curlFile);
```

#### fromBase64String

[](#frombase64string)

```
public function fromBase64String(string $base64String): self
```

Sets a base64 string representing an image as input for OCR processing.

**Parameters:**

- `$base64String` - Base64 string representing an image

```
$base64Image = base64_encode(file_get_contents('image.jpg'));
$client->fromBase64String($base64Image);
```

Configuration Methods
---------------------

[](#configuration-methods)

#### language

[](#language)

```
public function language(string|LanguageCodeEnum $language): self
```

Sets the language for OCR recognition.

**Parameters:**

- `$language` - Language code as string or LanguageCodeEnum instance

```
use LeaReift\OcrSpace\Enums\LanguageCodeEnum;

// Using enum
$client->language(LanguageCodeEnum::ENGLISH);

// Using string
$client->language('eng');
```

#### isOverlayRequired

[](#isoverlayrequired)

```
public function isOverlayRequired(bool $isRequired): self
```

Determines if overlay is required on the processed image.

**Parameters:**

- `$isRequired` - Boolean indicating if overlay is required

```
$client->isOverlayRequired(true);
```

#### detectOrientation

[](#detectorientation)

```
public function detectOrientation(bool $detectOrientation): self
```

Configures whether to automatically detect the image orientation.

**Parameters:**

- `$detectOrientation` - Boolean indicating if orientation should be detected

```
$client->detectOrientation(true);
```

#### fileType

[](#filetype)

```
public function fileType(string|FileTypeEnum $fileType): self
```

Sets the file type of the input image.

**Parameters:**

- `$fileType` - File type as string or FileTypeEnum instance

```
use LeaReift\OcrSpace\Enums\FileTypeEnum;

// Using enum
$client->fileType(FileTypeEnum::PDF);

// Using string
$client->fileType('pdf');
```

#### isCreateSearchablePdf

[](#iscreatesearchablepdf)

```
public function isCreateSearchablePdf(bool $isCreateSearchablePdf): self
```

Determines if a searchable PDF should be created.

**Parameters:**

- `$isCreateSearchablePdf` - Boolean indicating if a searchable PDF should be created

```
$client->isCreateSearchablePdf(true);
```

#### isSearchablePdfHideTextLayer

[](#issearchablepdfhidetextlayer)

```
public function isSearchablePdfHideTextLayer(bool $isSearchablePdfHideTextLayer): self
```

Determines if the text layer should be hidden in the searchable PDF.

**Parameters:**

- `$isSearchablePdfHideTextLayer` - Boolean indicating if the text layer should be hidden

```
$client->isSearchablePdfHideTextLayer(false);
```

#### scale

[](#scale)

```
public function scale(bool $scale): self
```

Determines if the image should be scaled to improve OCR recognition.

**Parameters:**

- `$scale` - Boolean indicating if the image should be scaled

```
$client->scale(true);
```

#### isTable

[](#istable)

```
public function isTable(bool $isTable): self
```

Configures if the image contains data in table format.

**Parameters:**

- `$isTable` - Boolean indicating if the image contains tables

```
$client->isTable(true);
```

#### engine

[](#engine)

```
public function engine(int $engine = 1): self
```

Sets the OCR engine to use.

**Parameters:**

- `$engine` - Integer representing the OCR engine (defaults to 1)

```
$client->engine(2);
```

#### options

[](#options)

```
public function options(): array
```

Returns an array with all currently configured options.

```
$options = $client->options();
print_r($options);
```

Complete Usage Example
----------------------

[](#complete-usage-example)

```
use LeaReift\OcrSpace\Client;
use LeaReift\OcrSpace\Enums\LanguageCodeEnum;

// Create client
$client = new Client('your-api-key-here');

// Configure options
$response = $client
    ->fromUrl('https://example.com/invoice.jpg')
    ->language(LanguageCodeEnum::ENGLISH)
    ->detectOrientation(true)
    ->isTable(true)
    ->engine(2)
    ->get();

// Process the response
if (!$response->is_errored_on_processing) {
    echo "Recognized text count: " . $response->parsed_results->count();
} else {
    echo "Error: " . $response->error_message;
}
```

Contributing
------------

[](#contributing)

Contributions are always welcome! Just open a Pull Request with your changes and I'll review it as soon as I can!

Credits
-------

[](#credits)

OCR.space is a service of [a9t9 software GmbH](https://a9t9.com/about). They are also in [github](https://github.com/A9T9)

This package is an independent development that is in no way linked to a9t9 software. I want to acknowledge a9t9 for put this OCR service online.

License
-------

[](#license)

This wrapper is made available under the MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance49

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.6% 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.

###  Release Activity

Cadence

Every ~2 days

Total

3

Last Release

376d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f726f33d9871b932d8d74d1d7cc85d9c1adc54898f131c61a68f9c5fbd01576e?d=identicon)[Lea-Reift](/maintainers/Lea-Reift)

---

Top Contributors

[![Lea-Reift](https://avatars.githubusercontent.com/u/32004646?v=4)](https://github.com/Lea-Reift "Lea-Reift (43 commits)")[![Enjoyzz](https://avatars.githubusercontent.com/u/1448659?v=4)](https://github.com/Enjoyzz "Enjoyzz (2 commits)")

---

Tags

curlocrocr-spacephp

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/lea-reift-ocr-space/health.svg)

```
[![Health](https://phpackages.com/badges/lea-reift-ocr-space/health.svg)](https://phpackages.com/packages/lea-reift-ocr-space)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M318](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M292](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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