The Best PHP API for Shipping Container OCR

Stop using regex. Extract structured data from Shipping Containers with 99% accuracy using PHP and cURL.

Shipping Container OCR extraction process diagram
StructOCR transforms raw Shipping Container images into validated JSON.

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.

1
Upload
2
Results

Drop files here or click to browse

JPG · PNG · WebP  ·  up to 500 files · max 4.5 MB each

No files selected
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

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

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 with 99% accuracy. 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 with 99% accuracy. 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 with 99% accuracy. 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 with 99% accuracy.

Java · Container
Tutorial

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.

PHP · HIN
Country Tutorial

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.

Python · občanský průkaz
Country Tutorial

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.

Python · cédula de identidad
Country Tutorial

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.

Python · cédula de ciudadanía
Country Tutorial

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.

Python · id-kaart

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 99.9% Uptime