dev-master
9999999-devLaravel OCR.space API Client
MIT
The Requires
- guzzlehttp/guzzle ~6.0
- php >=5.6.4
The Development Requires
by Juan Fuentes
laravel api service ocr
Laravel OCR.space API Client
Laravel (or just plain PHP) class for calling https://ocr.space/ free API, (*2)
This package provides an independent implementation of an OCR.space API client for Laravel (or PHP) applications, (*3)
OCR.API is a free/paid API for the OCR.space online service that converts images of text documents in text strings using OCR technologies, (*4)
To get OCR.space API just use the require command of composer or edit manually your composer.json, adding the require block (then you should run composer update):, (*5)
$ composer require jfuentestgn/ocr-space
{ "require": { "jfuentestgn/ocr-space": "dev-master" } }
After install the package, if you want to use it in a Laravel application, you should register the service provider. Add the OcrServiceProvider class to the list of providers in config/app.php:, (*6)
'providers' => [ .... JFuentesTgn\OcrSpace\OcrServiceProvider::class, ... ]
If you want to use the Facade version of the service, you could add an alias in config/app.php
:, (*7)
'aliases' => [ .... 'OCR' => JFuentesTgn\OcrSpace\OcrFacade::class, ... ]
This package requires an API key to work. First of all, register in the OCR API site to get a valid KEY, (*8)
Publish vendor assets to get a local copy of the config file:, (*9)
$ php artisan vendor:publish --provider=JFuentesTgn\\OcrSpace\\OcrServiceProvider
This will create a config/ocrspace.php
file in your app. Edit this file and update the API key configuration property, (*10)
In Laravel, you can use the OcrAPI class service as any other injected service. As an exemple:, (*11)
use JFuentesTgn\OcrSpace\OcrAPI; class TestController extends Controller { public function processImage(Request $request, OcrAPI $ocr) { // You can use the $ocr instance to call OCR.space web service $response = $ocr->parseImageFile($imageFile); } }
If you prefer to use the facade interface, you can do just this:, (*12)
$response = OCR::parseImageFile($imageFile);
Laravel is not a requirement for this package. If you need to use it outside a Laravel app, you can just create an instance of the API as with any other class:, (*13)
$ocr = new OcrAPI($apiKey); $response = $ocr->parseImageFile($imageFile);
In this case you MUST pass your API key as a parameter to the constructor, (*14)
The response (JFuentesTgn\OcrSpace\OcrResponse
) object returned by the OcrAPI methods maps JSON response from OCR.space online service in an object oriented way., (*15)
This is an example of how to read the service response:, (*16)
$image = 'snap_005.jpg'; $response = $ocr->parseImageFile($image); if ($response->length() == 1) { $text = $response->items(0)->text(); }
This package is maintained by Juan Fuentes, (*17)
OCR.space is a service of a9t9 software GmbH. They are also in github, (*18)
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, (*19)
Laravel OCR.space API is licensed under The MIT License (MIT)., (*20)
Laravel OCR.space API Client
MIT
laravel api service ocr