1

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.

4

2 回答 2

1

我们使用Zint Barcode GeneratorUnix 包来生成 QR 和 PDF417 代码。也支持皇家邮政。(在 CentOS 上dnf install zint,Ubuntu 需要更多的工作)。

Zint 文档:http ://www.zint.org.uk/

在 PHP 中使用该system方法,例如:

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

它将在请求的 $targetFilePath 上生成图像。

于 2016-04-12T14:37:25.730 回答
0

对于 PHP 中的 ECC200 Datamatrix Generation,我们成功地使用了:

sudo apt install dmtx-utils

要从服务器输出 PNG 文件,使用正常的 apache2 设置,当您在浏览器中输入时,您将获得 PNG 中的条形码:http: //yourserver.com/datamatrix/ ?in=yourbarcodetext

<?php
ob_start();
$old_path = getcwd();

$infile = "/var/www/html/datamatrix/message2.txt";
$image = "/var/www/html/datamatrix/image.png";

file_put_contents($infile,$_GET["in"]);

$ex = "export HOME=/tmp && /usr/bin/dmtxwrite {$infile} -o {$image}";

echo "<b>$ex</b>";
$output = shell_exec($ex);

echo var_export($output, TRUE);

echo "done";
chdir($old_path);

$im = imagecreatefrompng($image);

ob_end_clean();
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
于 2019-01-16T13:46:15.883 回答