以毫米(php)打印(生成)code128条形码(或任何图像)

时间:2013-02-08 13:33:39

标签: php printing barcode-printing code128

我需要在code128 barcodes中生成PHP的标签。 用户几乎可以使用任何打印机打印这些打印机。

我有一些特定的要求:

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

  • 最大整体条形码宽度:115毫米

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

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

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

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

提前致谢

4 个答案:

答案 0 :(得分:3)

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

我使用barcodegen找到的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可以改变。

在我的问题中,我有一个244px宽的图像,我需要它以超过95mm的打印。 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个像素?然后你将英寸转换为mm

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

答案 1 :(得分:0)

你好也许这个网址可能会有所帮助。由于各种打印机配置,毫米可能是您的关键点。但是,如果配置打印机,则没有问题。 网址:http://www.davidscotttufts.com/2009/03/31/how-to-create-barcodes-in-php/

答案 2 :(得分:0)

ZF条形码允许您更改数字的粗细。

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(); 

答案 3 :(得分:0)

我无法完全达到115毫米。这是我的三台打印机以及IE或Firefox上的打印尺寸略大于116mm的打印机。将宽度调整为19可以降低到约109毫米......

我为每个符号使用单独的png图像,并在客户端将它们串在一起。可以在http://notionovus.com/blog/barcodes/html/code-128-barcode/

找到使用此技术的完整Code128符号系统
<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">