Search code examples
phpdatamatrix

ECC200 Datamatrix Generation in PHP


Has anybody had any experience with generating 2D Barcodes for Royal Mail via PHP? I've spent a while attempting to get my own routines to write a valid datamatrix sadly to no avail.

I do have working conversion routines for ASCII to C40 and Luhn 16 checksum makers but just can't get anywhere with the graphical representation, or the ECC200 byte creation for that matter.

Are there any pre-written libraries out there with documentation that would help take away a lot of further legwork?

I do need to be able to generate this within the server environment, without using external sites ofr image generation ideally.


Solution

  • We use Zint Barcode Generator Unix packages for QR and PDF417 code generation. Royal Mail is supported as well. (on CentOS dnf install zint, Ubuntu takes more work).

    Zint documentation: http://www.zint.org.uk/

    In PHP use the system method, example:

    $targetFilePath = dirname(__FILE__).'/test.png';
    $contents = 'ABC123';
    system('zint ...params... -o"' . $targetFilePath . '" -d"' . $contents . '"');
    var_dump(file_exists($targetFilePath));
    

    It will generate an image on the requested $targetFilePath.