James
James

Reputation: 3283

PHP: Adjust output size of the barcode using Zend_Barcode | Magento Invoice Barcodes

I'm using the Zend_Barcode framework to generate barcodes for the first time in Magento with the intention of adding shipping barcodes to invoices.

The model appears to be fairly simple but I cannot change the size of the barcode.

If I sue this method:

$barcodeOptions = array('text' => 'ZEND-FRAMEWORK', 'width'=>400);
$rendererOptions = array('width'=> 400);
$renderer = Zend_Barcode::factory(
    'code128', 'image', $barcodeOptions, $rendererOptions
)->render();

I end up with a BARCODE that's 275px but an IMAGE that's 400px wide. i.e. The actual visible barcode is the same size as if no options are sent, but the actual image size is 400px.

Same if I use the draw method.

$barcodeOptions = array('text' => $barCodeNo, 'width'=> '400', 'height'=> '500'); 
$rendererOptions = array('width'=> '400', 'height'=> '500'); 
// Draw the barcode in a new image, 
$imageResource = Zend_Barcode::draw( 
    'code128', 'image', $barcodeOptions, $rendererOptions 
); 

imagejpeg($imageResource);

I can't find anything in the documentation apart from adding the size height and width into the options arrays, so what am I missing?

Any help would be appreciated.

Upvotes: 2

Views: 6637

Answers (1)

James
James

Reputation: 3283

Finally got it:

$barcodeOptions = array(
    'text' => $barCodeNo, 
    'barHeight'=> 74, 
    'factor'=>3.98,
);


$rendererOptions = array();
$renderer = Zend_Barcode::factory(
    'code128', 'image', $barcodeOptions, $rendererOptions
)->render();

'barHeight' sets the height of the barcode.
'factor' is an index that increases the size of the barcode relative. 3.98 = ~75mm which is what I needed.

Upvotes: 5

Related Questions