Search code examples
zend-frameworkbarcode

zend library for bar code image style in PHP


Is this possible to create bar code image like 'image1'. using Zend bar code library I create image(image2) but its diffrent. code mention below

$this->load->library('zend');
this->zend->load('Zend/Barcode');
$imageResource = Zend_Barcode::factory('code128', 'image', array('text' => "CMB5E65", 'barHeight'=> 50,'factor'=> 4), array())->draw();
imagepng($imageResource, $path);

image1

image2


Solution

  • The Zend Framework manual lists the barcode symbologies supported on this page:

    https://framework.zend.com/manual/2.1/en/modules/zend.barcode.objects.html

    The second barcode in your example will not fit in a UPC-A format, which is that used for your first example barcode. If your customer wants numeric data only, your code should look something like this:

    $this->load->library('zend');
    this->zend->load('Zend/Barcode');
    $imageResource = Zend_Barcode::factory('UPC-A', 'image', array('text' => "689076996624", 'barHeight'=> 50,'factor'=> 4), array())->draw();
    imagepng($imageResource, $path);
    

    I am not sure if the '4' at the end is generated by the library. My guess is that you have to create the checksum yourself.

    If, on the otherhand, your customer wants a barcode they can embed letters and symbols into, you have to use Code 128. On the Zend Framework page they mistakenly list the checksum as optional. I do not trust this.

    A barcode font is not just like Helvetica or Times New Roman you have to write some code to get it to look like something that will scan and that your customers will like.