anprsoftware / laravel-sdk
Laravel SDK for ANPR.Software — automatic number plate recognition API
Requires
- php: ^8.1
- illuminate/http: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-11-29 01:08:32 UTC
README
Automatic Number Plate Recognition for Laravel - Detect, read, and classify license plates from any image in seconds, and describe the vehicle they belong to.
Supported countries: United Kingdom, UAE, Saudi Arabia, Qatar, Kuwait, Bahrain, and Oman.
Returns the plate number, plate code, country, emirate (UAE), plate type (private, commercial, export etc.), plate size, plate color and text color - plus the vehicle's body type, color, brand, model and view angle.
$result = Anpr::detect($image); $plate = $result->firstPlate(); $plate->text->fullEn(); // "S 2393" $plate->text->plateCodeEn; // "S" $plate->text->plateNumberEn; // "2393" $plate->attributes->country; // "uae" $plate->attributes->emirate; // "dubai" $plate->text->minCharConfidence; // 0.91 $result->body->brand(); // "Toyota" $result->body->model(); // "Land Cruiser"
use Anpr\LaravelSdk\Enums\Country; $result = Anpr::detectCountry(Country::UnitedKingdom, $image); $plate = $result->firstPlate(); $plate->text->fullEn(); // "YF 15 ZGV" $plate->uk->region; // "Leeds" $plate->uk->period; // "Mar 2015 to Aug 2015"
Built for parking systems, gate access control, traffic monitoring, toll collection, and fleet management.
Sample Detections
| Short Plate | Long Plate |
|---|---|
![]() |
![]() |
| UAE · Dubai · White · Private · Short | UAE · Dubai · White · Private · Long |
| R 68434 | R 68434 |
Detection Pipeline
Plate localization with confidence scoring:
| Short Plate | Long Plate |
|---|---|
![]() |
![]() |
OCR Results
Per-character classification on cropped plates:
| Short Plate | Long Plate |
|---|---|
![]() |
![]() |
What It Does
- Plate Detection - Locate and extract license plates from full vehicle images
- OCR in English and Arabic - Read plate code and number with per-character confidence scores
- Classification - Identify country, emirate, plate color, type (private, taxi, diplomatic, police...), size and text color
- UK Registrations - Read UK number plates and decode the format, nation, issuing region and issue period
- Vehicle Recognition - Car recognition: body type, color, view angle, brand and model, on the same call or on their own
- Multi-Plate and Multi-Vehicle - Read every plate in an image and link each one to its vehicle
- Queued Frames - Submit bursts of camera frames for background processing
- Plate Logo - Replace the plate in a vehicle photo with your logo
- Bounding Box Coordinates - Get exact plate and vehicle positions for annotation or cropping
Supported Countries
| Country | Country enum |
Route value | Notes |
|---|---|---|---|
| United Kingdom | Country::UnitedKingdom |
uk |
Read with detectCountry() only |
| UAE | Country::Uae |
uae |
All 7 emirates |
| Saudi Arabia | Country::SaudiArabia |
saudi_arabia |
|
| Qatar | Country::Qatar |
qatar |
|
| Kuwait | Country::Kuwait |
kuwait |
|
| Bahrain | Country::Bahrain |
bahrain |
|
| Oman | Country::Oman |
oman |
Anpr::detect() works out the country by itself for every country except the United Kingdom. UK plates are read with Anpr::detectCountry(Country::UnitedKingdom, $image).
An account may be licensed for a subset of countries. Plates from a country you are not licensed for are withheld and listed in $result->unlicensed with their country and position only.
Requirements
- PHP 8.1+
- Laravel 10, 11, or 12
Installation
composer require anprsoftware/laravel-sdk
Add your API key to .env:
ANPR_API_KEY=your-api-key-here
That's it. The service provider and facade are auto-discovered.
Quick Start
Detect plates from an image
use Anpr\LaravelSdk\Facades\Anpr; $result = Anpr::detect('/path/to/car.jpg'); if ($result->hasPlates()) { foreach ($result->plates as $plate) { echo $plate->text->plateCodeEn; // "S" echo $plate->text->plateCodeAr; // "" echo $plate->text->plateNumberEn; // "2393" echo $plate->text->plateNumberAr; // "" echo $plate->text->fullEn(); // "S 2393" echo $plate->attributes->country; // "uae" echo $plate->attributes->emirate; // "dubai" echo $plate->attributes->color; // "white" echo $plate->attributes->type; // "private" echo $plate->attributes->textColor; // "black" echo $plate->detectionConfidence; // 0.95 echo $plate->text->confidence; // 0.946 echo $plate->text->minCharConfidence; // 0.91 // Per-character confidence scores foreach ($plate->text->characters as $char) { echo "{$char->char}: {$char->confidence}"; } } }
Every field of the API response can be read in snake_case or camelCase: $plate->text->plate_code_en and $plate->text->plateCodeEn are the same value. toArray() returns the raw response.
Confidence
A plate carries two kinds of score, and they fail independently:
$plate->detectionConfidence- how sure the detector is that a plate is there$plate->text->confidenceand$plate->text->minCharConfidence- the mean and the weakest of the per-character OCR scores
A plate number is not partially correct, so gate on the weakest character:
if ($plate->text->isConfident(0.8)) { // every character was read with at least 0.8 confidence }
$plate->quality reports how large the plate was in the image (plateWidthPx, plateHeightPx, band, note), which tells a weak read apart from a camera that did not give enough pixels.
Detect a known country (and UK plates)
When a camera only ever sees one country's plates, fix the country. It skips country classification, so it is faster - and it is the way to read UK plates.
use Anpr\LaravelSdk\Enums\Country; $result = Anpr::detectCountry(Country::UnitedKingdom, '/path/to/car.jpg'); $plate = $result->firstPlate(); echo $plate->text->fullEn(); // "YF 15 ZGV" echo $plate->attributes->type; // "current" echo $plate->uk->valid; // true echo $plate->uk->format; // "current" echo $plate->uk->nation; // "England" echo $plate->uk->region; // "Leeds" echo $plate->uk->period; // "Mar 2015 to Aug 2015" echo $plate->uk->periodFrom; // "2015-03" echo $plate->uk->periodTo; // "2015-08" echo $plate->uk->personalisedTag; // false
A UK plate has no code group: the whole registration is in plateNumberEn, spaced the way it is printed, and there is no Arabic text. attributes->type is the registration format (current, prefix, suffix, dateless, northern_ireland, ...). The uk block is decoded from the text read, so it is only as good as the read; the period is when marks with that age identifier were first issued, not the age of the vehicle.
A country can also be given as a string: Anpr::detectCountry('uae', $image).
Detection options
detect() and detectCountry() take an options array as their last argument:
$result = Anpr::detect($image, [], [ 'plate_only' => true, // skip vehicle analysis - faster, fewer credits 'main_only' => true, // only the main vehicle's plate ]);
| Option | Default | Description |
|---|---|---|
camera_id |
- | Logs an entry/exit movement for one of your cameras |
main_only |
false |
Return only the main vehicle's plate |
plate_only |
false |
Skip all vehicle analysis; $result->body is null |
all_cars |
false |
Describe every vehicle in the image ($result->cars) |
plate_attributes |
true |
false keeps the country and skips emirate, color, type, size and text color |
body, color, position, brand, car_model |
true |
Turn off one part of the vehicle analysis at a time |
Vehicle details
detect() describes the main vehicle alongside its plate:
$vehicle = $result->body; echo $vehicle->bodyType(); // "suv" echo $vehicle->colorName(); // "white" echo $vehicle->brand(); // "Toyota" echo $vehicle->model(); // "Land Cruiser" echo $vehicle->viewAngle(); // "front"
With all_cars, every vehicle is listed and each plate points at the vehicle it sits on:
$result = Anpr::detect($image, [], ['all_cars' => true]); foreach ($result->cars as $car) { echo "{$car->carId}: {$car->brand()} {$car->model()}"; // plates: $car->plateIds } echo $result->firstPlate()->carId;
To describe a vehicle without reading its plate:
$car = Anpr::car($image); // body type, color, view angle, brand, model $car = Anpr::car($image, ['car_model' => false]); // skip parts you do not need $car = Anpr::body($image); // body type only echo $car->body->brand(); // "Porsche" echo $car->body->bodyType(); // "coupe"
Read a cropped plate
When you already have a cropped plate image, skip detection:
$result = Anpr::read('/path/to/plate.jpg'); echo $result->text->fullEn(); // "S 2393" echo $result->attributes->emirate; // "dubai"
Detect from an uploaded file
public function scan(Request $request) { $request->validate(['image' => 'required|image|max:10240']); $result = Anpr::detect($request->file('image'), [ 'gate_id' => 'gate-entrance', ]); return response()->json([ 'plates' => $result->plateTexts(), // ["S 2393"] 'count' => $result->platesFound, ]); }
Queue frames for background processing
For many images at once, submit them as frames. The call returns immediately and the result is collected later, or delivered to your webhook.
$job = Anpr::submitFrame($image, ['lane' => 'entry'], ['camera_id' => 'cam-01']); echo $job->jobId; echo $job->status; // "queued" // Later $job = Anpr::frame($job->jobId); if ($job->isDone()) { $plates = $job->result()->plateTexts(); }
Frames accept the detection options, plus:
| Option | Description |
|---|---|
country |
Fix the plate country, e.g. Country::UnitedKingdom |
coalesce |
Keep only the newest frame per camera (requires camera_id); older ones end as superseded and are not billed |
wait |
Seconds to hold the request open (up to 60); when the frame finishes in time, $job->result() is available straight away |
Job status is one of queued, processing, done, superseded, failed - see isPending(), isDone(), isSuperseded() and isFailed(). Jobs are kept for one hour. Anpr::frameQueue() returns the current queue status.
Replace a plate with a logo
$result = Anpr::plateLogo('/path/to/car.jpg', '/path/to/logo.png', [ 'logo_scale' => 1.3, 'plate_color' => 'white', ]); $result->save(storage_path('app/car-branded.jpg')); echo $result->header('X-Plate-Bbox'); // "302,802,899,970"
Options: logo_scale, padding (and padding_top / padding_right / padding_bottom / padding_left), padding_unit (percent or px), plate_color, border_color, border_width, fit (contain or stretch), plate_expand (and its per-side variants). An InvalidImageException is thrown when no plate is found in the image.
Check usage and credits
$usage = Anpr::usage(days: 7); echo $usage->tier; // "free" echo $usage->creditsRemaining(); // 94 echo $usage->requestsRemaining(); // 997 echo $usage->rateLimitPerMinute(); // 20 echo $usage->usageThisMonth['requests']; // 3 echo $usage->usageThisMonth['plates_detected']; // 2 echo $usage->usageThisMonth['cost']; // 0.03 foreach ($usage->dailyUsage as $day) { echo "{$day->date}: {$day->requests} requests, {$day->platesDetected} plates"; }
Calls are metered in credits: one per plate processed and one per vehicle analyzed, with a minimum of one per image. Every result carries what the call used in $result->credits and $result->cost.
Health check
$health = Anpr::health(); echo $health->status; // "healthy" echo $health->isHealthy(); // true echo $health->models['ocr']; // true
Custom Parameters
Attach metadata to a detect(), detectCountry(), read() or submitFrame() request. Parameters are forwarded to your webhook endpoint as-is - useful for tracking which camera, gate, or location triggered the detection.
$result = Anpr::detect($image, [ 'location' => 'gate-1', 'building_id' => 'tower-a', 'lane' => 'entry', ]);
Webhooks
Webhooks are configured in the ANPR.Software dashboard. When a detection is made, the API forwards the result - along with any custom params you included in the request - to your configured webhook URL.
This allows you to receive real-time detection results without polling. For example, passing gate_id as a param lets your webhook handler know exactly where the detection originated.
// Your detection request with custom params $result = Anpr::detect($image, [ 'gate_id' => 'entrance-1', 'building_id' => 'tower-a', ]); // The webhook payload your endpoint receives will include: // { // "event": "plate_detected", // "data": { ... detection result ... }, // "params": { "gate_id": "entrance-1", "building_id": "tower-a" } // }
Error Handling
All exceptions extend AnprException so you can catch broadly or specifically:
use Anpr\LaravelSdk\Exceptions\AnprException; use Anpr\LaravelSdk\Exceptions\AuthenticationException; use Anpr\LaravelSdk\Exceptions\RateLimitException; use Anpr\LaravelSdk\Exceptions\InsufficientBalanceException; use Anpr\LaravelSdk\Exceptions\InvalidImageException; use Anpr\LaravelSdk\Exceptions\NotFoundException; try { $result = Anpr::detect($image); } catch (RateLimitException $e) { // Per-minute limit: retry after the given time. Null when the monthly limit was reached. $retryAfter = $e->retryAfterSeconds; } catch (InsufficientBalanceException $e) { // Out of credits Log::warning("Out of credits: {$e->available} remaining, {$e->required} required"); } catch (InvalidImageException $e) { // Bad image, invalid parameters, or no plate found for plateLogo() } catch (AuthenticationException $e) { // Missing or invalid API key, or a blocked account } catch (NotFoundException $e) { // Unknown camera, or an unknown or expired frame job } catch (AnprException $e) { // Catch-all for any API error }
| Exception | HTTP status |
|---|---|
InvalidImageException |
400, 422 |
AuthenticationException |
401, 403 |
InsufficientBalanceException |
402 |
NotFoundException |
404 |
RateLimitException |
429 |
ServerException |
5xx and anything else |
Testing
The SDK ships with a test fake that follows Laravel's Notification::fake() pattern - no HTTP requests are made during tests.
use Anpr\LaravelSdk\Facades\Anpr; public function test_gate_opens_for_authorized_plate(): void { $fake = Anpr::fake(); // ... your application logic that calls Anpr::detect() ... $fake->assertDetectCalled(times: 1); $fake->assertDetectCalledWithParams(['gate_id' => 'gate-01']); }
Every method returns a realistic default response. detectCountry() returns a UK plate for uk and a UAE plate otherwise.
$fake->assertDetectCountryCalled('uk'); $fake->assertDetectCalledWithOptions(['plate_only' => true]); $fake->assertCalled('read'); $fake->assertCalled('submitFrame', times: 2); $fake->assertNothingCalled();
You can also provide custom responses with fakeDetection(), fakeCountryDetection(), fakeRead(), fakeCar(), fakeFrame(), fakePlateLogo(), fakeUsage() and fakeHealth():
use Anpr\LaravelSdk\Data\DetectionResult; $fake = Anpr::fake(); $fake->fakeDetection(DetectionResult::fromArray([ 'success' => true, 'plates_found' => 1, 'plates' => [[ 'plate_id' => 0, 'detection_confidence' => 0.99, 'text' => [ 'plate_code_en' => 'X', 'plate_code_ar' => 'س', 'plate_number_en' => '99999', 'plate_number_ar' => '٩٩٩٩٩', 'confidence' => 0.98, 'min_char_confidence' => 0.95, ], 'attributes' => [ 'country' => 'uae', 'emirate' => 'abudhabi', 'color' => 'white', 'type' => 'private', 'size' => 'long', 'text_color' => 'black', ], ]], 'cost' => 0.005, 'credits' => 1, 'timestamp' => '2026-11-26T14:30:00.000000', ]));
Configuration
Publish the config file:
php artisan vendor:publish --tag=anpr-config
All options can be set via environment variables:
| Variable | Default | Description |
|---|---|---|
ANPR_API_KEY |
- | Your API key |
ANPR_BASE_URL |
https://api.anpr.software |
API base URL |
ANPR_API_VERSION |
v1 |
API version |
ANPR_TIMEOUT |
30 |
Request timeout in seconds |
ANPR_RETRY_TIMES |
3 |
Number of attempts on server errors |
ANPR_RETRY_SLEEP_MS |
200 |
Delay between attempts in ms |
API Methods
| Method | Returns | Description |
|---|---|---|
Anpr::detect($image, $params, $options) |
DetectionResult |
Full pipeline: vehicle, plates, classification, OCR |
Anpr::detectCountry($country, $image, $params, $options) |
DetectionResult |
Same, with the country fixed. Required for UK plates |
Anpr::read($image, $params, $options) |
ReadResult |
Read a pre-cropped plate image |
Anpr::car($image, $options) |
VehicleResult |
Vehicle body type, color, view angle, brand and model |
Anpr::body($image) |
VehicleResult |
Vehicle body type only |
Anpr::submitFrame($image, $params, $options) |
FrameJob |
Queue an image for background detection |
Anpr::frame($jobId) |
FrameJob |
Status and result of a queued frame |
Anpr::frameQueue() |
array |
Frame queue status |
Anpr::plateLogo($image, $logo, $options) |
PlateLogoResult |
Replace the plate with a logo |
Anpr::usage($days) |
UsageResult |
Usage stats and remaining credits |
Anpr::health() |
HealthResult |
API and model readiness status |
Image Input
All methods that take an image accept:
// File path Anpr::detect('/path/to/image.jpg'); // Uploaded file from request Anpr::detect($request->file('image')); // Raw image contents Anpr::detect(Storage::get('cars/image.jpg')); // Stream resource Anpr::detect(fopen('/path/to/image.jpg', 'r')); // SplFileInfo Anpr::detect(new SplFileInfo('/path/to/image.jpg'));
Upgrading
$plate->confidenceis now$plate->detectionConfidence(the old name still works). OCR scores are in$plate->text->confidenceand$plate->text->minCharConfidence.- Characters in
$plate->text->charactersexposechar,ocrClass,script,confidenceandbbox(previouslyclassandconfidence). Anpr::usage()returns nestedcredits,limitsandusageThisMonth; usecreditsRemaining()andrequestsRemaining().- Custom
TransportInterfaceimplementations need the new$queryargument onpostMultipart()and the newpostFiles()method. CustomAnprClientInterfaceimplementations need the new methods.
Related
- UK number plate recognition API
- UAE license plate recognition software
- Saudi Arabia license plate recognition
- Qatar license plate recognition
- Kuwait license plate recognition
- Bahrain license plate recognition
- Oman license plate recognition
- Car recognition API
- Car brand recognition API
- Car model recognition API
- ANPR software for parking and access control
- Arabic license plate recognition
- Smart parking ANPR platform
- API documentation
License
MIT





