我第一次使用 Zend_Barcode 框架在 Magento 中生成条形码,目的是将运输条形码添加到发票中。
模型看起来相当简单,但我无法更改条形码的大小。
如果我起诉这个方法:
$barcodeOptions = array('text' => 'ZEND-FRAMEWORK', 'width'=>400);
$rendererOptions = array('width'=> 400);
$renderer = Zend_Barcode::factory(
'code128', 'image', $barcodeOptions, $rendererOptions
)->render();
我最终得到的条形码是 275 像素,但图像是 400 像素宽。即实际可见条形码的大小与未发送选项时的大小相同,但实际图像大小为 400px。
如果我使用绘制方法也是如此。
$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);
除了将尺寸高度和宽度添加到选项数组中之外,我在文档中找不到任何内容,那么我缺少什么?
如有任何帮助,我们将不胜感激。
最佳答案
终于明白了:
$barcodeOptions = array(
'text' => $barCodeNo,
'barHeight'=> 74,
'factor'=>3.98,
);
$rendererOptions = array();
$renderer = Zend_Barcode::factory(
'code128', 'image', $barcodeOptions, $rendererOptions
)->render();
'barHeight' 设置条形码的高度。
“因子”是增加条形码相对大小的索引。 3.98 = ~75mm,这就是我所需要的。
关于PHP:使用 Zend_Barcode 调整条形码的输出大小 | Magento 发票条形码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15804657/