-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGeneratedCodebar.php
More file actions
77 lines (62 loc) · 2.14 KB
/
GeneratedCodebar.php
File metadata and controls
77 lines (62 loc) · 2.14 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* TODO 测试版,请不下下载使用
*/
namespace barcode\barcode;
use yii\base\Exception;
require_once('class' . DIRECTORY_SEPARATOR . 'BCGColor.php');
require_once('class' . DIRECTORY_SEPARATOR . 'BCGBarcode.php');
require_once('class' . DIRECTORY_SEPARATOR . 'BCGDrawing.php');
require_once('class' . DIRECTORY_SEPARATOR . 'BCGFontFile.php');
include_once('class' . DIRECTORY_SEPARATOR . 'BCGcode128.barcode.php');
/**
*
* Class GeneratedCodebar
* @package barcode\barcode
*/
class GeneratedCodebar extends \yii\base\Widget
{
public $message;
public function init()
{
parent::init();
if ($this->message == null) {
throw new Exception('wrong message');
}
}
public function run()
{
/* $className = 'BCGcodabar';
$baseClassFile = 'BCGBarcode1D.php';
$codeVersion = '5.0.2';*/
$color_black = new \BCGColor(0, 0, 0);
$color_white = new \BCGColor(255, 255, 255);
$filetypes = array('PNG' => \BCGDrawing::IMG_FORMAT_PNG, 'JPEG' => \BCGDrawing::IMG_FORMAT_JPEG, 'GIF' => \BCGDrawing::IMG_FORMAT_GIF);
$code_generated = new \BCGcode128();
$this->baseCustomSetup($code_generated);
$code_generated->setScale(max(1, min(4, 4)));
$code_generated->setBackgroundColor($color_white);
$code_generated->setForegroundColor($color_black);
$code_generated->parse($this->message);
$drawing = new \BCGDrawing('', $color_white);
$drawing->setBarcode($code_generated);
$drawing->setRotationAngle(0);
$drawing->setDPI(72);
$drawing->draw();
header('Content-Type: image/png');
$drawing->finish($filetypes['PNG']);
return "Hello!";
}
public function baseCustomSetup($barcode)
{
$font_dir = 'font';
$barcode->setThickness(max(9, min(90, 25)));
$font = new \BCGFontFile(__DIR__.'/font/Arial.ttf', 15);
$barcode->setFont($font);
}
/* public function customSetup($barcode, $get) {
if (isset($get['checksum'])) {
$barcode->setChecksum($get['checksum'] === '1' ? true : false);
}
}*/
}