2

我需要用code128 barcodesin生成标签PHP。这些将由用户使用几乎任何打印机打印。

我有一些特定的要求:

  • 窄条宽度应在 0.375mm 和 0.5mm 之间

  • 最大整体条码宽度:115mm

  • 前 8 位数字必须使用子集 B
  • 剩下的 20 位数字必须使用子集 C
  • 代码必须在高速下可读

我尝试了几个条形码库,但大多数都不允许以毫米为单位说明最小条宽。您只能以固定的整数增量缩放窄条宽度,1 太小,2 太大:)

我还尝试使用 gd lib 重新采样图像,但代码在高速下变得不可读。

我应该构建自己的代码生成器吗?如果是这样,我将如何生成以毫米为单位的条形图?

提前致谢

4

4 回答 4

3

好的,我相信我找到了一个不适用于所有浏览器和打印机组合的解决方案,但它非常适合我。

我正在使用barodegen php 库,因为它是唯一一个允许我为某些字符指定一个子集而为其他字符指定另一个子集的库。

在我的具体问题中,我可以这样做:

$setB = '%'.substr($vars->code, 0, 7);
$setC = substr($vars->code, 7);

$code_array = array(array(CODE128_B, $setB), array(CODE128_C, $setC));

然后将 $code_array 解析为条形码。

现在,通过设置生成的条形码图像的每英寸点数,也可以简单地解决另一个问题。我错误地认为这被称为 DPI。如果我弄错了,请纠正我,但 DPI 是打印机的硬件特性。你无法改变这一点。另一方面,您可以更改 PPI。

在我的问题中,我有一个 244 像素宽的图像,我需要它打印超过 95 毫米。barcodegen 允许您通过调用来执行此操作

$drawing->setDPI(64);
// I do think they should rename this to setPPI

现在,当你有一个 64ppi 的 224px 图像后,你需要做的就是在一个 img 标签中显示它,如下所示:

<img style="width: 96.8375mm;" src="interlink_code128_barcode.php?code='.$code128.'" border="0">

96.8375mm是通过求解简单方程得到的,如果图像一英寸包含64个像素,那么244个像素将占据多少英寸?然后你将英寸转换为毫米

我还没有确认可以高速读取条形码,但我确实看到打印输出看起来很清晰!:D

于 2013-02-22T19:38:56.210 回答
0

我无法准确地达到 115 毫米。这是一个可以在我的所有三台打印机以及 IE 或 Firefox 上以 116 毫米多一点的速度打印。将宽度调整为 19 可使您降至约 109 毫米...

我为每个符号使用单独的 png 图像,并在客户端将它们串在一起。使用这种技术的完整Code128符号系统可以在http://notionovus.com/blog/barcodes/html/code-128-barcode/找到

<img 
alt="104,{Start B}" title="104,{Start B}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AC3gAT0BDuLeG4IAAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 33,A:{A},B:{A}" title=" 33,A:{A},B:{A}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AFzgAZsBPUCFhSIAAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 34,A:{B},B:{B}" title=" 34,A:{B},B:{B}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AHTgAcsBVYSvxaMAAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 35,A:{C},B:{C}" title=" 35,A:{C},B:{C}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AHcgAREAmJf+YHwAAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 36,A:{D},B:{D}" title=" 36,A:{D},B:{D}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AE7gAX8BL1PJL4YAAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 37,A:{E},B:{E}" title=" 37,A:{E},B:{E}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AHLgAccBU7KPeu8AAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 38,A:{F},B:{F}" title=" 38,A:{F},B:{F}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AHOgAYkBFLOchfoAAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 39,A:{G},B:{G}" title=" 39,A:{G},B:{G}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AC7gAT8BDxDJjdQAAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 40,A:{H},B:{H}" title=" 40,A:{H},B:{H}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADrgAVcBG9SQg7wAAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 99,A:{Switch C},B:{Switch C}" title=" 99,A:{Switch C},B:{Switch C}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AEQgAKsAZaZph30AAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 01,A:{!},B:{!}" title=" 01,A:{!},B:{!}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADJgAMcAkzbyVIUAAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 23,A:{7},B:{7}" title=" 23,A:{7},B:{7}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ABIgAEcAM15OsZIAAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 45,A:{M},B:{M}" title=" 45,A:{M},B:{M}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AETgAWsBJQmo7lIAAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 67,A:{ETX},B:{c}" title=" 67,A:{ETX},B:{c}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AHpgAVcA2+hRyrMAAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 89,A:{EM},B:{y}" title=" 89,A:{EM},B:{y}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ACQgAGsARQRcPq8AAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 01,A:{!},B:{!}" title=" 01,A:{!},B:{!}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADJgAMcAkzbyVIUAAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 23,A:{7},B:{7}" title=" 23,A:{7},B:{7}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ABIgAEcAM15OsZIAAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 45,A:{M},B:{M}" title=" 45,A:{M},B:{M}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AETgAWsBJQmo7lIAAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 67,A:{ETX},B:{c}" title=" 67,A:{ETX},B:{c}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AHpgAVcA2+hRyrMAAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 89,A:{EM},B:{y}" title=" 89,A:{EM},B:{y}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ACQgAGsARQRcPq8AAAAASUVORK5CYII=" width="20" height="30"><img
alt=" 46,A:{N},B:{N}" title=" 46,A:{N},B:{N}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AEcgALEAaE/9r8gAAAAASUVORK5CYII=" width="20" height="30"><img
alt="106,{Stop}"title="106,{Stop}"src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAABAQMAAAA/57ZEAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADigARMA2dpJzT8AAAAASUVORK5CYII=" width="20" height="30">
于 2013-02-13T11:51:45.830 回答
0

ZF Barcode 将允许您更改大量数字。

http://framework.zend.com/manual/1.12/en/zend.barcode.creation.html

它支持code128。

  $config = new Zend_Config(array(
                    'barcode' => 'code128',
                    'barcodeParams' => array('text' => 'ZEND-FRAMEWORK', 'thickWidth' => 10, 'thinWidth' => 5),
                    'renderer' => 'image',
                    'rendererParams' => array('imageType' => 'gif'),
                ));
  Zend_Barcode::factory($config)->render(); 
于 2013-02-08T13:59:38.380 回答
0

您好,也许这个网址可能会有所帮助。由于个别打印机配置,毫米可能是您的症结所在。但是,如果正在配置打印机,则没有问题。网址:http ://www.davidscotttufts.c​​om/2009/03/31/how-to-create-barcodes-in-php/

于 2013-02-08T13:45:03.247 回答