Index.php
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace addons\barcode\controller;
use think\addons\Controller;
use think\Response;
/**
* 条码生成
* @package addons\barcode\controller
*/
class Index extends Controller {
public function index() {
return $this->view->fetch();
}
// 生成条码
public function build() {
$text = $this->request->get('text', '1234567890');
$type = $this->request->get('type', 'C128');
$foreground = $this->request->get('foreground', "#000000");
$width = $this->request->get('width', 2);
$height = $this->request->get('height', 30);
$params = [
'text' => $text,
'type' => $type,
'foreground' => $foreground,
'width' => $width,
'height' => $height,
];
$barcode = \addons\barcode\library\Service::barcode($params);
// 直接显示条码
$response = Response::create()->header("Content-Type", "image/png");
header('Content-Type: image/png');
$response->content($barcode);
return $response;
}
}