I used Zend barcode library to generate barcodes for inventory items in my CodeIgniter project. And used the following code to do that.
public function gen_barcode($product_code = NULL, $bcs = 'code128', $height = 60, $text = 1)
{
$drawText = ($text != 1) ? FALSE : TRUE;
$this->load->library('zend');
$this->zend->load('Zend/Barcode');
$barcodeOptions = array('text' => $product_code, 'barHeight' => $height, 'drawText' => $drawText, 'factor' => 1.0);
if (0) {
$rendererOptions = array('imageType' => 'jpg', 'horizontalPosition' => 'center', 'verticalPosition' => 'middle');
$imageResource = Zend_Barcode::render($bcs, 'image', $barcodeOptions, $rendererOptions);
return $imageResource;
} else {
$rendererOptions = array('renderer' => 'svg', 'horizontalPosition' => 'center', 'verticalPosition' => 'middle');
$imageResource = Zend_Barcode::render($bcs, 'svg', $barcodeOptions, $rendererOptions);
header("Content-Type: image/svg+xml");
echo $imageResource;
}
}
But the barcode image doesn't generate correctly. The generated image is as follows :
Can anyone help ?