Intelligent Mail Barcode

USPS Intelligent Mail Barcode in PHP: tracking and routing code input, code examples and SVG output

The Intelligent Mail Barcode replaced POSTNET and PLANET with one symbol carrying both routing and tracking: a 20-digit tracking code, then optionally a routing code of 5, 9 or 11 digits after a dash.

The result is always 65 four-state bars. Getting there takes an 11-bit cyclic redundancy check and a conversion through 13-bit codewords, which is where the bcmath extension earns its place: without it the library falls back to its own arbitrary precision arithmetic.

Type Token

ItemValue
Type tokenIMB
Enum caseBarcodeType::IMB
FamilyPostal
StandardUSPS-B-3200
Class\Com\Tecnick\Barcode\Type\Linear\Imb

Input

ItemValue
Character setdigits, with - separating the tracking code from the routing code
Length20 digits, optionally followed by - and 5, 9 or 11 digits
Checkan 11-bit CRC, computed by the library
Extra parametersnone

Examples

Tracking and routing

<?php

require_once __DIR__ . '/vendor/autoload.php';

$barcode = new \Com\Tecnick\Barcode\Barcode();
$bobj = $barcode->getBarcodeObj(
    type: 'IMB',
    code: '01234567094987654321-01234567891',
    width: -3,
    height: -30,
    color: 'black',
    padding: [0, 0, 0, 0],
)->setBackgroundColor('white');

echo $bobj->getInlineSvgCode();

Intelligent Mail Barcode barcode encoding 01234567094987654321-01234567891

Tracking only

$bobj = $barcode->getBarcodeObj(
    type: 'IMB',
    code: '01234567094987654321',
    width: -3,
    height: -30,
    color: 'black',
    padding: [0, 0, 0, 0],
)->setBackgroundColor('white');

Intelligent Mail Barcode barcode encoding 01234567094987654321

Errors

These payloads raise \Com\Tecnick\Barcode\Exception:

PayloadMessage
0123456709498765432AInvalid tracking number

See Also