Download the PHP package erajkhatiwada/imb without Composer
On this page you can find all versions of the php package erajkhatiwada/imb. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download erajkhatiwada/imb
More information about erajkhatiwada/imb
Files in erajkhatiwada/imb
Package imb
Short Description A lightweight PHP library for encoding and decoding USPS Intelligent Mail Barcodes (IMB)
License CC0-1.0
Homepage https://github.com/erajkhatiwada/imb
Informations about the package imb
IMB - USPS Intelligent Mail Barcode Library for PHP
A lightweight PHP library for encoding and decoding USPS Intelligent Mail Barcodes (IMB).
Note: This is a PHP port/wrapper of the original Node.js library BossRoxall/imb created by BossRoxall. All credit for the original algorithm implementation goes to the original author.
Features
- Encode postal information into 65-character IMB barcode strings
- Decode IMB barcode strings back to postal data
- Error correction for damaged barcodes
- Full validation of input data
- CLI tool for command-line operations
- PSR-4 autoloading compatible
- PHPStan Level 8 compatible
- 100% test coverage ready
Installation
Via Composer
Manual Installation
- Clone the repository
- Run
composer install
Quick Start
Encoding
Decoding
Validation
Stringify
Convert IMB data to a concatenated numeric string (useful for display or comparison):
Input Fields
Required Fields
| Field | Description | Format |
|---|---|---|
barcode_id |
Barcode identifier | 2 digits, second digit must be 0-4 |
service_type |
Service type code | 3 digits |
mailer_id |
USPS mailer ID | 6 or 9 digits |
serial_num |
Serial number | Varies (mailer_id + serial_num = 15 digits) |
Optional Fields (Routing)
| Field | Description | Format |
|---|---|---|
zip |
ZIP code | 5 digits |
plus4 |
ZIP+4 extension | 4 digits (requires zip) |
delivery_pt |
Delivery point | 2 digits |
Output Format
The barcode is a 65-character string using only these characters:
- A - Ascending bar
- D - Descending bar
- F - Full bar (both ascending and descending)
- T - Track bar (neither ascending nor descending)
CLI Usage
The library includes a command-line interface:
Advanced Usage
Using IMBData Objects
Using Encoder/Decoder Directly
Error Handling
Damaged Barcode Recovery
The decoder can attempt to recover damaged barcodes:
API Reference
IMB (Static Facade)
| Method | Description |
|---|---|
encode(array\|IMBData $data): string |
Encode to barcode |
decode(string $barcode): DecodeResult |
Decode barcode |
decodeToArray(string $barcode): array |
Decode to array |
validate(array\|IMBData $data): bool |
Validate input data |
validateBarcode(string $barcode): bool |
Validate barcode string |
stringify(array\|IMBData $data): string |
Convert to numeric string |
createData(array $data): IMBData |
Create IMBData object |
getEncoder(): Encoder |
Get encoder instance |
getDecoder(): Decoder |
Get decoder instance |
IMBData
| Property | Type | Description |
|---|---|---|
barcodeId |
string | 2-digit barcode ID |
serviceType |
string | 3-digit service type |
mailerId |
string | 6 or 9 digit mailer ID |
serialNum |
string | Serial number |
zip |
?string | 5-digit ZIP |
plus4 |
?string | 4-digit ZIP+4 |
deliveryPt |
?string | 2-digit delivery point |
| Method | Description |
|---|---|
fromArray(array $data): IMBData |
Create from associative array |
toArray(): array |
Convert to associative array |
stringify(): string |
Convert to concatenated numeric string |
getMailerIdLength(): int |
Get mailer ID length (6 or 9) |
hasNineDigitMailerId(): bool |
Check if 9-digit mailer ID |
DecodeResult
| Property | Type | Description |
|---|---|---|
data |
IMBData | Decoded data |
message |
?string | Status message |
suggest |
?string | Suggested correction |
highlight |
?array | Positions that differ |
Testing
Requirements
- PHP 7.4 or higher
- No external dependencies for runtime
- PHPUnit 9.6+ for testing (dev)
License
This project is released under the CC0 1.0 Universal (Public Domain) license, same as the original Node.js library.
Acknowledgments
This PHP library is a direct port of the excellent Node.js IMB library created by BossRoxall. The encoding/decoding algorithms, bit permutation tables, and overall architecture are derived from that original work.
Special thanks to:
- BossRoxall - Author of the original Node.js IMB library
- Bob Codes - Original IMB algorithm implementation (released under CC0)
- USPS - Intelligent Mail Barcode specification
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Related Projects
- BossRoxall/imb - Original Node.js implementation (the source of this port)