Question

I need to generate labels with code128 barcodes in PHP. These will be printed by users with almost any printer.

I have some specific sets of requirements:

  • narrow bar width should be between 0.375mm and 0.5mm

  • maximum overall barcode width: 115mm

  • first 8 digits must use subset B
  • remaining 20 digits must use subset C
  • code must be readable at high speeds

I tried several barcode libraries but most of them don't allow stating the minimum bar width in millimeters. You are just able to scale the narrow bar width in fixed integer increments, and 1 is too small and 2 is too big :)

I also tried resampling the image using the gd lib, but the code becomes unreadable at high speeds.

Should I build my own code generator? If so, how would I generate the bars in millimeters?

Thanks in advance

Était-ce utile?

La solution

Ok, I believe I found a solution that applies not to every browser and printer combination, but it suits me nicely.

I am using the barodegen php library found at barcodegen because it is the only one allowing me to specify a subset for some characters and another one for others.

In my specific problem, I can do this:

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

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

And then parse $code_array into a barcode.

Now, the other problem is also simply solved by setting the point per inch of the generated barcode image. This is called, wrongly I think, DPI. Correct me if I'm mistaken, but DPI is a harware characteristic of a printer. You can't change that. PPI on the other hand, you can change.

In my problem I had a 244px wide image, and I needed it to print in more than 95mm. barcodegen allows you to do this by calling

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

Now, after you have a 224px image with 64ppi, all you need to do is show it in an img tag like this:

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

the 96.8375mm is obtained by solving the simple equation, if the image contains 64 pixels in one inch, how much inches will occupy 244 pixels? And then you transform inches to mm

I haven't got confirmation that the barcodes can be read at high speeds, but I do see the printouts looking sharp! :D

Autres conseils

Hello perhaps this url may be of help. Millimeters may be your sticking point, because of individual printer configurations. However, if are configuring the printer, than no problem. The URL: http://www.davidscotttufts.com/2009/03/31/how-to-create-barcodes-in-php/

ZF Barcode will allow you to change thick of digits.

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

ans it supports 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(); 

I was unable to hit 115mm exactly. Here's one that will print at a little over 116mm on all three of my printers and from IE or Firefox. Adjusting the width to 19 gets you down to about 109mm...

I am using a separate png image for each symbol and stringing them together on the client side. The complete Code128 symbology using this technique can be found at 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">
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top