1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Trait QROptionsTrait |
4
|
|
|
* |
5
|
|
|
* @filesource QROptionsTrait.php |
6
|
|
|
* @created 10.03.2018 |
7
|
|
|
* @package chillerlan\QRCode |
8
|
|
|
* @author smiley <[email protected]> |
9
|
|
|
* @copyright 2018 smiley |
10
|
|
|
* @license MIT |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace chillerlan\QRCode; |
14
|
|
|
|
15
|
|
|
use chillerlan\QRCode\Data\QRMatrix; |
16
|
|
|
|
17
|
|
|
trait QROptionsTrait{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* QR Code version number |
21
|
|
|
* |
22
|
|
|
* [1 ... 40] or QRCode::VERSION_AUTO |
23
|
|
|
* |
24
|
|
|
* @var int |
25
|
|
|
*/ |
26
|
|
|
protected $version = QRCode::VERSION_AUTO; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Minimum QR version (if $version = QRCode::VERSION_AUTO) |
30
|
|
|
* |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
protected $versionMin = 1; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Maximum QR version |
37
|
|
|
* |
38
|
|
|
* @var int |
39
|
|
|
*/ |
40
|
|
|
protected $versionMax = 40; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Error correct level |
44
|
|
|
* |
45
|
|
|
* QRCode::ECC_X where X is |
46
|
|
|
* L => 7% |
47
|
|
|
* M => 15% |
48
|
|
|
* Q => 25% |
49
|
|
|
* H => 30% |
50
|
|
|
* |
51
|
|
|
* @var int |
52
|
|
|
*/ |
53
|
|
|
protected $eccLevel = QRCode::ECC_L; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Mask Pattern to use |
57
|
|
|
* |
58
|
|
|
* [0...7] or QRCode::MASK_PATTERN_AUTO |
59
|
|
|
* |
60
|
|
|
* @var int |
61
|
|
|
*/ |
62
|
|
|
protected $maskPattern = QRCode::MASK_PATTERN_AUTO; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Add a "quiet zone" (margin) according to the QR code spec |
66
|
|
|
* |
67
|
|
|
* @var bool |
68
|
|
|
*/ |
69
|
|
|
protected $addQuietzone = true; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Size of the quiet zone |
73
|
|
|
* |
74
|
|
|
* internally clamped to [0 ... $moduleCount / 2], defaults to 4 modules |
75
|
|
|
* |
76
|
|
|
* @var int |
77
|
|
|
*/ |
78
|
|
|
protected $quietzoneSize = 4; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* QRCode::OUTPUT_MARKUP_XXXX where XXXX = HTML, SVG |
82
|
|
|
* QRCode::OUTPUT_IMAGE_XXX where XXX = PNG, GIF, JPG |
83
|
|
|
* QRCode::OUTPUT_STRING_XXXX where XXXX = TEXT, JSON |
84
|
|
|
* QRCode::OUTPUT_CUSTOM |
85
|
|
|
* |
86
|
|
|
* @var string |
87
|
|
|
*/ |
88
|
|
|
protected $outputType = QRCode::OUTPUT_IMAGE_PNG; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* the FQCN of the custom QROutputInterface if $outputType is set to QRCode::OUTPUT_CUSTOM |
92
|
|
|
* |
93
|
|
|
* @var string |
94
|
|
|
*/ |
95
|
|
|
protected $outputInterface; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* /path/to/cache.file |
99
|
|
|
* |
100
|
|
|
* @var string |
101
|
|
|
*/ |
102
|
|
|
protected $cachefile; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* newline string [HTML, SVG, TEXT] |
106
|
|
|
* |
107
|
|
|
* @var string |
108
|
|
|
*/ |
109
|
|
|
protected $eol = PHP_EOL; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* size of a QR code pixel [SVG, IMAGE_*] |
113
|
|
|
* HTML -> via CSS |
114
|
|
|
* |
115
|
|
|
* @var int |
116
|
|
|
*/ |
117
|
|
|
protected $scale = 5; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* a common css class |
121
|
|
|
* |
122
|
|
|
* @var string |
123
|
|
|
*/ |
124
|
|
|
protected $cssClass; |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* SVG opacity |
128
|
|
|
* |
129
|
|
|
* @var float |
130
|
|
|
*/ |
131
|
|
|
protected $svgOpacity = 1.0; |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* anything between <defs> |
135
|
|
|
* |
136
|
|
|
* @see https://developer.mozilla.org/docs/Web/SVG/Element/defs |
137
|
|
|
* |
138
|
|
|
* @var string |
139
|
|
|
*/ |
140
|
|
|
protected $svgDefs = '<style>rect{shape-rendering:crispEdges}</style>'; |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* string substitute for dark |
144
|
|
|
* |
145
|
|
|
* @var string |
146
|
|
|
*/ |
147
|
|
|
protected $textDark = '🔴'; |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* string substitute for light |
151
|
|
|
* |
152
|
|
|
* @var string |
153
|
|
|
*/ |
154
|
|
|
protected $textLight = '⭕'; |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* toggle base64 or raw image data |
158
|
|
|
* |
159
|
|
|
* @var bool |
160
|
|
|
*/ |
161
|
|
|
protected $imageBase64 = true; |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* toggle transparency, not supported by jpg |
165
|
|
|
* |
166
|
|
|
* @var bool |
167
|
|
|
*/ |
168
|
|
|
protected $imageTransparent = true; |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @see imagecolortransparent() |
172
|
|
|
* |
173
|
|
|
* @var array [R, G, B] |
174
|
|
|
*/ |
175
|
|
|
protected $imageTransparencyBG = [255, 255, 255]; |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @see imagepng() |
179
|
|
|
* |
180
|
|
|
* @var int |
181
|
|
|
*/ |
182
|
|
|
protected $pngCompression = -1; |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @see imagejpeg() |
186
|
|
|
* |
187
|
|
|
* @var int |
188
|
|
|
*/ |
189
|
|
|
protected $jpegQuality = 85; |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Module values map |
193
|
|
|
* |
194
|
|
|
* HTML : #ABCDEF, cssname, rgb(), rgba()... |
195
|
|
|
* IMAGE: [63, 127, 255] // R, G, B |
196
|
|
|
* |
197
|
|
|
* @var array |
198
|
|
|
*/ |
199
|
|
|
protected $moduleValues = [ |
200
|
|
|
// light |
201
|
|
|
QRMatrix::M_DATA => false, // 4 |
202
|
|
|
QRMatrix::M_FINDER => false, // 6 |
203
|
|
|
QRMatrix::M_SEPARATOR => false, // 8 |
204
|
|
|
QRMatrix::M_ALIGNMENT => false, // 10 |
205
|
|
|
QRMatrix::M_TIMING => false, // 12 |
206
|
|
|
QRMatrix::M_FORMAT => false, // 14 |
207
|
|
|
QRMatrix::M_VERSION => false, // 16 |
208
|
|
|
QRMatrix::M_QUIETZONE => false, // 18 |
209
|
|
|
QRMatrix::M_TEST => false, // 255 |
210
|
|
|
// dark |
211
|
|
|
QRMatrix::M_DARKMODULE << 8 => true, // 512 |
212
|
|
|
QRMatrix::M_DATA << 8 => true, // 1024 |
213
|
|
|
QRMatrix::M_FINDER << 8 => true, // 1536 |
214
|
|
|
QRMatrix::M_ALIGNMENT << 8 => true, // 2560 |
215
|
|
|
QRMatrix::M_TIMING << 8 => true, // 3072 |
216
|
|
|
QRMatrix::M_FORMAT << 8 => true, // 3584 |
217
|
|
|
QRMatrix::M_VERSION << 8 => true, // 4096 |
218
|
|
|
QRMatrix::M_TEST << 8 => true, // 65280 |
219
|
|
|
]; |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Sets the options, called internally by the constructor |
223
|
|
|
* |
224
|
|
|
* @return void |
225
|
|
|
* @throws \chillerlan\QRCode\QRCodeException |
226
|
|
|
*/ |
227
|
|
|
public function QROptionsTrait():void{ |
228
|
|
|
|
229
|
|
|
if(!array_key_exists($this->eccLevel, QRCode::ECC_MODES)){ |
230
|
|
|
throw new QRCodeException('Invalid error correct level: '.$this->eccLevel); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
if(!is_array($this->imageTransparencyBG) || count($this->imageTransparencyBG) < 3){ |
234
|
|
|
$this->imageTransparencyBG = [255, 255, 255]; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
$this->version = (int)$this->version; |
238
|
|
|
|
239
|
|
|
// clamp min/max version number |
240
|
|
|
$max = $this->versionMax; |
241
|
|
|
$min = $this->versionMin; |
242
|
|
|
$this->versionMin = (int)min($min, $max); |
243
|
|
|
$this->versionMax = (int)max($min, $max); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
} |
247
|
|
|
|