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.
Live Demo: Container OCR
No registration required. Upload a file to test the extraction.
Drop files here or click to browse
JPG · PNG · WebP · up to 500 files · max 4.5 MB each
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 200 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: < 4s (Average)
- •Uptime: 99.9% 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.
You May Also Like
Related tutorials, platform guides, and comparisons
Go Shipping Container OCR API
Upload an image for a free test! Tutorial: Learn how to use the StructOCR Go Client to extract data from Shipping Containers. Extract ISO 6346 container numbers with 99% accuracy. Includes code samples and JSON schema.
C# Shipping Container OCR API
Upload an image for a free test! Tutorial: Learn how to use the StructOCR C# Client to extract data from Shipping Containers. Extract ISO 6346 container numbers with 99% accuracy. Includes code samples and JSON schemas.
Python Shipping Container OCR API
Tutorial: Learn how to use the StructOCR Python SDK for shipping container OCR. Upload an image for a free test! Extract ISO 6346 container numbers with 99% accuracy. Includes code samples and JSON schemas.
Node.js Shipping Container OCR API
Tutorial: How to use the StructOCR Node.js SDK to extract data from Shipping Containers. Upload an image for a free test! Includes code samples and JSON schema.
Java Shipping Container OCR API
Upload an image for a free test! Tutorial: Learn how to use the StructOCR Java Client to extract data from Shipping Containers. Extract ISO 6346 container numbers with 99% accuracy.
PHP HIN (Hull Identification Number) OCR API
Tutorial: How to use the StructOCR PHP API to extract HIN from images. Upload an image for a free test! Includes native cURL code samples and marine OCR solutions.
Czech Republic Občanský průkaz OCR Python SDK
Python Tutorial: Automate KYC in the Czech Republic. Extract Czech text with diacritics, Rodné číslo, and validate TD1 MRZ from Občanský průkaz.
Chile Cédula OCR Python SDK
Python Tutorial: Automate KYC in Chile. Extract data from the Chilean Cédula de Identidad using StructOCR Python SDK. Supports RUN/RUT extraction and native Spanish text parsing.
Colombia Cédula OCR Python SDK
Python Tutorial: Automate KYC in Colombia. Extract data from the Colombian Cédula de Ciudadanía using StructOCR Python SDK. Supports NUIP extraction and complex address parsing.
Estonia ID-kaart OCR Python SDK
Python Tutorial: Automate KYC in Estonia. Extract data from the Estonian Identity Card (ID-kaart) using StructOCR Python SDK. Supports native text, Isikukood, and MRZ extraction.
Technical Comparisons & Integrations
Explore platform integrations and competitive analysis
Tesseract OCR vs. StructOCR API for ISO 6346 Container Numbers
A technical comparison for developers evaluating open-source Tesseract vs. a dedicated cloud API for extracting shipping container numbers.
Add Container OCR to Your v0 App in 5 Minutes
Step-by-step guide to integrating the StructOCR shipping container API into a v0 by Vercel app. Build logistics and yard management tools with zero backend.
Add Container OCR to Your Bolt.new App in 5 Minutes
Step-by-step guide to integrating the StructOCR shipping container API into a Bolt.new app. Build logistics and yard management tools right in your browser.
Add Container OCR using Cursor in 5 Minutes
Step-by-step guide to integrating the StructOCR shipping container API using the Cursor AI code editor. Build logistics and yard management tools rapidly.
Google Cloud Vision vs. StructOCR API for Shipping Containers
Comparing generic enterprise OCR solutions like Google Cloud Vision against StructOCR's purpose-built API for ISO 6346 shipping container recognition.
Add Container OCR to Your Lovable.dev App in 5 Minutes
Step-by-step guide to integrating the StructOCR shipping container API into a Lovable.dev app. Build logistics and yard management tools with zero backend.
From tutorial to production in 5 minutes.
You've seen the code. Now get your API key, grab your 200 free credits, and see it work with your own images. No credit card required.