我需要在PHP
中使用code128 barcodes
生成标签。这些将由用户使用几乎任何打印机打印。
我有一些特定的要求:
-
窄条宽度应在0.375mm和0.5mm 之间
-
最大整体条形码宽度:115mm
- 前8位必须使用子集B
- 剩下的20位必须使用子集C
- 代码必须具有高速可读性
我尝试了几个条形码库,但大多数都不允许以毫米为单位说明最小条形码宽度。您只能以固定的整数增量缩放窄条宽度,1太小,2太大:)
我还尝试使用gd-lib对图像进行重新采样,但代码在高速时变得不可读。
我应该构建自己的代码生成器吗?如果是,我将如何生成以毫米为单位的条形图?
提前感谢
好吧,我相信我找到了一个解决方案,它并不适用于所有的浏览器和打印机组合,但它非常适合我。
我使用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可以改变。
在我的问题中,我有一个244像素宽的图像,我需要它打印超过95毫米。条形码生成允许您通过调用来完成此操作
$drawing->setDPI(64);
// I do think they should rename this to setPPI
现在,在你有了一个224px的64ppi图像后,你所需要做的就是在一个img标签中显示它,如下所示:
<img style="width: 96.8375mm;" src="interlink_code128_barcode.php?code='.$code128.'" border="0">
96.8375mm是通过求解简单方程获得的,如果图像在一英寸中包含64个像素,那么有多少英寸会占用244个像素?然后将英寸转换为毫米
我还没有确认条形码可以高速读取,但我确实看到打印出来的东西看起来很锋利!:D
你好,也许这个url会有所帮助。由于打印机配置不同,毫米可能是您的症结所在。但是,如果正在配置打印机,则没有问题。URL:http://www.davidscotttufts.com/2009/03/31/how-to-create-barcodes-in-php/
ZF条形码将允许您更改数字的粗细。
http://framework.zend.com/manual/1.12/en/zend.barcode.creation.html
并且它支持代码128。
$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();
我无法准确命中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">