first commit
This commit is contained in:
37
class/smarty_plugins/function.insert_barcode.php
Normal file
37
class/smarty_plugins/function.insert_barcode.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty plugin.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty {insert_barcode} plugin.
|
||||
*
|
||||
* Type: function<br>
|
||||
* Name: insert_barcode<br>
|
||||
* Purpose: inserts inline SVG barcode
|
||||
*
|
||||
* @param array $params parameters
|
||||
* @param Smarty_Internal_Template $smarty
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function smarty_function_insert_barcode($params, &$smarty)
|
||||
{
|
||||
if (($params['type'] ?? '') == 'EAN13') {
|
||||
$params['code'] = formatEAN($params['code']);
|
||||
}
|
||||
|
||||
try {
|
||||
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
||||
$result = $generator->getBarcode($params['code'] ?? '', $params['type'] ?? $generator::TYPE_CODE_128, $params['width'] ?? 2, $params['height'] ?? 30);
|
||||
} catch (\Picqer\Barcode\Exceptions\BarcodeException $e) {
|
||||
$result = '';
|
||||
}
|
||||
|
||||
if (!empty($params['assign'])) {
|
||||
$smarty->assign($params['assign'], $result);
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user