The Best PHP API for Shipping Container OCR
Stop using regex. Extract structured data from Shipping Containers with 99% accuracy using PHP and cURL.

The Problem with Shipping Container Parsing in PHP
Handling image processing and OCR directly within PHP backends is resource-intensive and error-prone. When dealing with shipping containers, legacy PHP libraries and open-source wrappers struggle with physical damage, severe rust, skewed angles, and vertical text. Attempting to stitch together basic OCR tools often leads to fragile regular expression pipelines, high server load, and unacceptable failure rates in production.
The StructOCR Solution
StructOCR allows you to offload the heavy computational lifting from your PHP servers to our specialized deep learning API. With a simple cURL request, our service guarantees ISO 6346 compliant extraction. Our system automatically handles deskewing, perspective correction, and vertical text reading, providing an accurate, structured JSON response that is ideal for backend integration in logistics and port automation platforms.
Common Use Cases
- Terminal Automation: Speed up gate operations and yard management by instantly capturing container numbers.
- Customs & Compliance: Automate cross-border document verification and manifesting.
- Asset Tracking: Monitor shipping container movements across the global supply chain with real-time data.
Implementation: Raw API Request (PHP cURL)
Complete, runnable PHP code to extract data from a Shipping Container via HTTP request.
Prerequisite: PHP 7.4+ with cURL extension enabled
<?php
// 💰 Save 30%+ vs competitors. Get 20 free credits instantly:
// 👉 https://structocr.com/register
$imagePath = '/path/to/your/container_image.jpg'; // Replace with the actual path to your image
$apiKey = 'YOUR_API_KEY'; // Replace with your actual API key
// 1. Read the image file and encode it to Base64
$imageData = file_get_contents($imagePath);
if ($imageData === false) {
die('Failed to read image file.');
}
$base64Image = base64_encode($imageData);
// 2. Prepare the API request payload
$payload = json_encode(['img' => $base64Image]);
// 3. Initialize cURL session targeting the container endpoint
$ch = curl_init('https://api.structocr.com/v1/container');
// 4. Configure cURL options
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'x-api-key: ' . $apiKey,
'Content-Type: application/json'
],
]);
// 5. Execute the API request
$response = curl_exec($ch);
// 6. Check for cURL errors
if (curl_errno($ch)) {
die('cURL error: ' . curl_error($ch));
}
// 7. Close cURL session
curl_close($ch);
// 8. Decode the JSON response
$decodedResponse = json_decode($response, true);
// 9. Handle the API response
if ($decodedResponse === null) {
die('Failed to decode JSON response: ' . $response);
}
if (isset($decodedResponse['success']) && $decodedResponse['success']) {
$data = $decodedResponse['data'];
echo "✅ Extraction Successful!\n";
echo "Container Number: " . $data['container_number'] . "\n";
echo "Is Valid (ISO 6346): " . ($data['is_valid'] ? 'Yes' : 'No') . "\n";
echo "Confidence: " . $data['confidence'] . "\n\n";
$parsed = $data['parsed'];
echo "--- Parsed Details ---\n";
echo "Owner Code: " . $parsed['owner_code'] . "\n";
echo "Category: " . $parsed['category'] . "\n";
echo "Serial Number: " . $parsed['serial_number'] . "\n";
echo "Check Digit: " . $parsed['check_digit'] . "\n";
} else {
echo "❌ Error: " . ($decodedResponse['error'] ?? 'Unknown API error') . "\n";
}
?>Technical Specs
- •Latency: < 5s (Average)
- •Uptime: 98.5% SLA
- •Security: AES-256 Encryption & SOC2 Compliant
- •Input: JPG, PNG, WebP (Max 4.5MB)
- •Output: JSON (Structured Data)
Key Features
- •Smart Crop: Auto-detects container boundaries.
- •ISO 6346 Validation: Cross-validates owner codes and checksums automatically.
- •Specialized Models: Trained specifically on vertical and degraded Shipping Container text.
Sample JSON Response
The API returns a clean JSON object with normalized, parsed container fields.
{
"success": true,
"data": {
"container_number": "TTNU5194822",
"is_valid": true,
"confidence": "High",
"parsed": {
"owner_code": "TTN",
"category": "U",
"serial_number": "519482",
"check_digit": "2"
}
}
}Frequently Asked Questions
What file formats are supported?
JPG, PNG, and WebP images up to 4.5MB.
Is data stored?
No. Images are processed in-memory and deleted immediately.
How to handle errors?
Check the 'success' flag and 'error' message in the response.
More OCR Tutorials
PHP Driver License OCR SDK
Struggling with manual driver's license data entry? Our PHP OCR SDK provides AES-256 encrypted, SOC2 compliant data extraction in <5s, ensuring 98.5% uptime.
PHP HIN (Hull Identification Number) OCR API
Tutorial: How to use the StructOCR PHP API to extract Hull Identification Numbers (HIN) from images. Includes native cURL code samples and marine OCR solutions.
PHP Invoice Line Item OCR API
Struggling with manual invoice data entry? Our PHP invoice line item OCR API processes documents in <5s, outputting structured JSON. SOC2 compliant & AES-256 encrypted.
PHP National ID OCR API
High-accuracy National ID OCR for PHP. Get structured JSON output from ID card images. A superior alternative to Tesseract. No complex PHP SDK needed.
Precise Data Extraction and Seamless
Integration with AI-powered OCR API.
Empower your solutions with automated data extraction by
integrating best-in class StructOCR via API seamlessly.
No credit card required • Full API access included