The Best PHP API for Shipping Container OCR

Stop using regex. Extract structured data from shipping containers 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.
Need more testing? Create a free account to get 200 free credits (equals 200 Container scans).

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 EXAMPLE
<?php

// Get 200 free credits:
// 👉 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)
  • •Availability: Served from Cloudflare's global edge network
  • •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?

Only briefly. Uploaded images and results are kept for at most 24 hours for quality spot-checks, then deleted.

How to handle errors?

Check the 'success' flag and 'error' message in the response.

You May Also Like

Related tutorials, platform guides, and comparisons

Tutorial

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 and check them against the ISO check digit. Includes code samples and JSON schema.

Go · Container
Tutorial

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 and check them against the ISO check digit. Includes code samples and JSON schemas.

C# · Container
Tutorial

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 and check them against the ISO check digit. Includes code samples and JSON schemas.

Python · Container
Tutorial

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.

Node.js · Container
Tutorial

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 and check them against the ISO check digit.

Java · Container
Tutorial

PHP Weighbridge Ticket OCR API Tutorial

Integrate weighbridge ticket OCR in PHP. Extract ticket number, vehicle, material, gross, tare, net, and validation data from Base64 images.

PHP · Weighbridge Ticket
Tutorial

Node.js Weighbridge Ticket OCR API Tutorial

Build a Node.js weighbridge ticket OCR integration. Extract ticket, vehicle, material, gross, tare, and net weights with the official StructOCR SDK.

Node.js · Weighbridge Ticket
Country Tutorial

Algeria CNIBE (Biometric ID) OCR Python SDK

Python Tutorial: Automate KYC in Algeria. Extract bilingual text and validate TD1 MRZ from CNIBE (Biometric ID) using StructOCR Python SDK.

Python · cnibe (biometric id)
Tutorial

Node.js Receipt OCR API SDK

Tutorial: Integrate the StructOCR Node.js SDK to extract structured data from retail receipts. Upload an image for a free test! Parse merchants, totals, and line items in your Javascript backends.

Node.js · Receipt
Country Tutorial

Argentina DNI OCR Python SDK

Python Tutorial: Automate KYC in Argentina. Extract Spanish text, CUIL/CUIT, and validate TD1 MRZ from DNI using StructOCR Python SDK.

Python · dni

Technical Comparisons & Integrations

Explore platform integrations and competitive analysis

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.

Instant Access Cancel Anytime No Credit Card