28 lines
975 B
PHP
28 lines
975 B
PHP
<?php
|
|
|
|
namespace addons\barcode\library;
|
|
|
|
|
|
class Service
|
|
{
|
|
public static function barcode($params)
|
|
{
|
|
$params = is_array($params) ? $params : [$params];
|
|
$params['text'] = isset($params['text']) ? $params['text'] : 'Hello world!';
|
|
$params['type'] = isset($params['type']) ? $params['type'] : 'C128';
|
|
$params['width'] = isset($params['width']) ? $params['width'] : 2;
|
|
$params['height'] = isset($params['height']) ? $params['height'] : 30;
|
|
$params['foreground'] = isset($params['foreground']) ? $params['foreground'] : "#000000";
|
|
|
|
// 前景色
|
|
list($r, $g, $b) = sscanf($params['foreground'], "#%02x%02x%02x");
|
|
$foregroundcolor = [$r, $g, $b];
|
|
|
|
// 创建实例
|
|
$generator = new \Picqer\Barcode\BarcodeGeneratorPNG();
|
|
$barcode = $generator->getBarcode($params['text'], $params['type'], $params['width'], $params['height'], $foregroundcolor);
|
|
|
|
return $barcode;
|
|
}
|
|
}
|