annotate vendor/endroid/qr-code/src/QrCode.php @ 6:cec75ba50afc

endroid/qrcode as distributed
author Charlie Root
date Sat, 13 Jan 2018 09:00:52 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1 <?php
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
2
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
3 /*
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
4 * (c) Jeroen van den Enden <info@endroid.nl>
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
5 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
6 * This source file is subject to the MIT license that is bundled
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
7 * with this source code in the file LICENSE.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
8 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
9
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
10 namespace Endroid\QrCode;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
11
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
12 use Endroid\QrCode\Exceptions\DataDoesntExistsException;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
13 use Endroid\QrCode\Exceptions\FreeTypeLibraryMissingException;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
14 use Endroid\QrCode\Exceptions\ImageFunctionFailedException;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
15 use Endroid\QrCode\Exceptions\VersionTooLargeException;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
16 use Endroid\QrCode\Exceptions\ImageSizeTooLargeException;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
17 use Endroid\QrCode\Exceptions\ImageFunctionUnknownException;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
18 use ReflectionFunction;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
19
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
20 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
21 * Generate QR Code.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
22 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
23 class QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
24 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
25 /** @const int Error Correction Level Low (7%) */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
26 const LEVEL_LOW = 1;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
27
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
28 /** @const int Error Correction Level Medium (15%) */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
29 const LEVEL_MEDIUM = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
30
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
31 /** @const int Error Correction Level Quartile (25%) */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
32 const LEVEL_QUARTILE = 3;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
33
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
34 /** @const int Error Correction Level High (30%) */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
35 const LEVEL_HIGH = 2;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
36
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
37 /** @const string Image type png */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
38 const IMAGE_TYPE_PNG = 'png';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
39
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
40 /** @const string Image type gif */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
41 const IMAGE_TYPE_GIF = 'gif';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
42
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
43 /** @const string Image type jpeg */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
44 const IMAGE_TYPE_JPEG = 'jpeg';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
45
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
46 /** @const string Image type wbmp */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
47 const IMAGE_TYPE_WBMP = 'wbmp';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
48
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
49 /** @const int Horizontal label alignment to the center of image */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
50 const LABEL_HALIGN_CENTER = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
51
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
52 /** @const int Horizontal label alignment to the left side of image */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
53 const LABEL_HALIGN_LEFT = 1;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
54
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
55 /** @const int Horizontal label alignment to the left border of QR Code */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
56 const LABEL_HALIGN_LEFT_BORDER = 2;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
57
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
58 /** @const int Horizontal label alignment to the left side of QR Code */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
59 const LABEL_HALIGN_LEFT_CODE = 3;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
60
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
61 /** @const int Horizontal label alignment to the right side of image */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
62 const LABEL_HALIGN_RIGHT = 4;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
63
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
64 /** @const int Horizontal label alignment to the right border of QR Code */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
65 const LABEL_HALIGN_RIGHT_BORDER = 5;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
66
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
67 /** @const int Horizontal label alignment to the right side of QR Code */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
68 const LABEL_HALIGN_RIGHT_CODE = 6;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
69
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
70 /** @const int Vertical label alignment to the top */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
71 const LABEL_VALIGN_TOP = 1;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
72
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
73 /** @const int Vertical label alignment to the top and hide border */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
74 const LABEL_VALIGN_TOP_NO_BORDER = 2;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
75
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
76 /** @const int Vertical label alignment to the middle*/
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
77 const LABEL_VALIGN_MIDDLE = 3;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
78
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
79 /** @const int Vertical label alignment to the bottom */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
80 const LABEL_VALIGN_BOTTOM = 4;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
81
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
82 /** @var string */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
83 protected $logo = null;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
84
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
85 protected $logo_size = 48;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
86
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
87 /** @var string */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
88 protected $text = '';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
89
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
90 /** @var int */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
91 protected $size = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
92
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
93 /** @var int */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
94 protected $padding = 16;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
95
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
96 /** @var bool */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
97 protected $draw_quiet_zone = false;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
98
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
99 /** @var bool */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
100 protected $draw_border = false;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
101
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
102 /** @var array */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
103 protected $color_foreground = array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
104
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
105 /** @var array */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
106 protected $color_background = array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
107
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
108 /** @var string */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
109 protected $label = '';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
110
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
111 /** @var int */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
112 protected $label_font_size = 16;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
113
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
114 /** @var string */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
115 protected $label_font_path = '';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
116
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
117 /** @var int */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
118 protected $label_halign = self::LABEL_HALIGN_CENTER;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
119
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
120 /** @var int */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
121 protected $label_valign = self::LABEL_VALIGN_MIDDLE;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
122
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
123 /** @var resource */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
124 protected $image = null;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
125
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
126 /** @var int */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
127 protected $version;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
128
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
129 /** @var int */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
130 protected $error_correction = self::LEVEL_MEDIUM;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
131
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
132 /** @var array */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
133 protected $error_corrections_available = array(
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
134 self::LEVEL_LOW,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
135 self::LEVEL_MEDIUM,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
136 self::LEVEL_QUARTILE,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
137 self::LEVEL_HIGH,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
138 );
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
139
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
140 /** @var int */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
141 protected $module_size;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
142
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
143 /** @var string */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
144 protected $image_type = self::IMAGE_TYPE_PNG;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
145
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
146 /** @var array */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
147 protected $image_types_available = array(
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
148 self::IMAGE_TYPE_GIF,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
149 self::IMAGE_TYPE_PNG,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
150 self::IMAGE_TYPE_JPEG,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
151 self::IMAGE_TYPE_WBMP,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
152 );
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
153
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
154 /** @var string */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
155 protected $image_path;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
156
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
157 /** @var string */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
158 protected $path;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
159
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
160 /** @var int */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
161 protected $structure_append_n;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
162
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
163 /** @var int */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
164 protected $structure_append_m;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
165
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
166 /** @var int */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
167 protected $structure_append_parity;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
168
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
169 /** @var string */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
170 protected $structure_append_original_data;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
171
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
172 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
173 * Class constructor.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
174 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
175 * @param string $text
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
176 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
177 public function __construct($text = '')
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
178 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
179 $this->setPath(__DIR__.'/../assets/data');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
180 $this->setImagePath(__DIR__.'/../assets/image');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
181 $this->setLabelFontPath(__DIR__.'/../assets/font/opensans.ttf');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
182 $this->setText($text);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
183 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
184
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
185 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
186 * Set structure append.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
187 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
188 * @param int $n
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
189 * @param int $m
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
190 * @param int $parity Parity
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
191 * @param string $original_data Original data
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
192 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
193 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
194 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
195 public function setStructureAppend($n, $m, $parity, $original_data)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
196 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
197 $this->structure_append_n = $n;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
198 $this->structure_append_m = $m;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
199 $this->structure_append_parity = $parity;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
200 $this->structure_append_original_data = $original_data;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
201
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
202 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
203 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
204
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
205 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
206 * Set QR Code version.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
207 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
208 * @param int $version QR Code version
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
209 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
210 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
211 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
212 public function setVersion($version)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
213 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
214 if ($version <= 40 && $version >= 0) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
215 $this->version = $version;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
216 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
217
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
218 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
219 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
220
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
221 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
222 * Return QR Code version.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
223 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
224 * @return int
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
225 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
226 public function getVersion()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
227 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
228 return $this->version;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
229 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
230
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
231 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
232 * Set QR Code error correction level.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
233 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
234 * @param mixed $error_correction Error Correction Level
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
235 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
236 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
237 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
238 public function setErrorCorrection($error_correction)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
239 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
240 if (!is_numeric($error_correction)) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
241 $level_constant = 'Endroid\QrCode\QrCode::LEVEL_'.strtoupper($error_correction);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
242 $error_correction = constant($level_constant);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
243 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
244
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
245 if (in_array($error_correction, $this->error_corrections_available)) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
246 $this->error_correction = $error_correction;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
247 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
248
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
249 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
250 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
251
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
252 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
253 * Return QR Code error correction level.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
254 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
255 * @return int
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
256 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
257 public function getErrorCorrection()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
258 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
259 return $this->error_correction;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
260 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
261
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
262 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
263 * Set QR Code module size.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
264 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
265 * @param int $module_size Module size
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
266 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
267 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
268 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
269 public function setModuleSize($module_size)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
270 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
271 $this->module_size = $module_size;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
272
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
273 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
274 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
275
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
276 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
277 * Return QR Code module size.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
278 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
279 * @return int
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
280 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
281 public function getModuleSize()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
282 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
283 return $this->module_size;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
284 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
285
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
286 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
287 * Set image type for rendering.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
288 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
289 * @param string $image_type Image type
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
290 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
291 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
292 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
293 public function setImageType($image_type)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
294 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
295 if (in_array($image_type, $this->image_types_available)) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
296 $this->image_type = $image_type;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
297 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
298
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
299 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
300 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
301
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
302 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
303 * Return image type for rendering.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
304 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
305 * @return string
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
306 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
307 public function getImageType()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
308 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
309 return $this->image_type;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
310 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
311
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
312 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
313 * Set image type for rendering via extension.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
314 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
315 * @param string $extension Image extension
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
316 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
317 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
318 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
319 public function setExtension($extension)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
320 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
321 if ($extension == 'jpg') {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
322 $this->setImageType('jpeg');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
323 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
324 $this->setImageType($extension);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
325 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
326
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
327 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
328 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
329
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
330 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
331 * Set path to the images directory.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
332 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
333 * @param string $image_path Image directory
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
334 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
335 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
336 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
337 public function setImagePath($image_path)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
338 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
339 $this->image_path = $image_path;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
340
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
341 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
342 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
343
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
344 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
345 * Return path to the images directory.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
346 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
347 * @return string
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
348 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
349 public function getImagePath()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
350 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
351 return $this->image_path;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
352 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
353
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
354 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
355 * Set path to the data directory.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
356 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
357 * @param string $path Data directory
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
358 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
359 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
360 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
361 public function setPath($path)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
362 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
363 $this->path = $path;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
364
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
365 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
366 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
367
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
368 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
369 * Return path to the data directory.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
370 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
371 * @return string
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
372 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
373 public function getPath()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
374 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
375 return $this->path;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
376 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
377
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
378 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
379 * Set logo in QR Code.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
380 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
381 * @param string $logo Logo Path
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
382 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
383 * @throws Exceptions\DataDoesntExistsException
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
384 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
385 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
386 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
387 public function setLogo($logo)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
388 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
389 if (!file_exists($logo)) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
390 throw new DataDoesntExistsException("$logo file does not exist");
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
391 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
392
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
393 $this->logo = $logo;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
394
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
395 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
396 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
397
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
398 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
399 * Set logo size in QR Code(default 48).
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
400 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
401 * @param int $logo_size Logo Size
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
402 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
403 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
404 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
405 public function setLogoSize($logo_size)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
406 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
407 $this->logo_size = $logo_size;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
408
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
409 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
410 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
411
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
412 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
413 * Set text to hide in QR Code.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
414 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
415 * @param string $text Text to hide
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
416 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
417 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
418 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
419 public function setText($text)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
420 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
421 $this->text = $text;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
422
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
423 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
424 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
425
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
426 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
427 * Return text that will be hid in QR Code.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
428 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
429 * @return string
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
430 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
431 public function getText()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
432 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
433 return $this->text;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
434 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
435
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
436 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
437 * Set QR Code size (width).
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
438 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
439 * @param int $size Width of the QR Code
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
440 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
441 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
442 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
443 public function setSize($size)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
444 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
445 $this->size = $size;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
446
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
447 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
448 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
449
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
450 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
451 * Return QR Code size (width).
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
452 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
453 * @return int
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
454 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
455 public function getSize()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
456 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
457 return $this->size;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
458 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
459
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
460 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
461 * Set padding around the QR Code.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
462 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
463 * @param int $padding Padding around QR Code
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
464 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
465 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
466 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
467 public function setPadding($padding)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
468 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
469 $this->padding = $padding;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
470
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
471 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
472 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
473
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
474 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
475 * Return padding around the QR Code.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
476 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
477 * @return int
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
478 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
479 public function getPadding()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
480 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
481 return $this->padding;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
482 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
483
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
484 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
485 * Set draw required four-module wide margin.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
486 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
487 * @param bool $draw_quiet_zone State of required four-module wide margin drawing
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
488 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
489 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
490 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
491 public function setDrawQuietZone($draw_quiet_zone)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
492 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
493 $this->draw_quiet_zone = $draw_quiet_zone;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
494
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
495 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
496 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
497
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
498 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
499 * Return draw required four-module wide margin.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
500 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
501 * @return bool
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
502 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
503 public function getDrawQuietZone()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
504 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
505 return $this->draw_quiet_zone;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
506 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
507
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
508 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
509 * Set draw border around QR Code.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
510 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
511 * @param bool $draw_border State of border drawing
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
512 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
513 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
514 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
515 public function setDrawBorder($draw_border)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
516 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
517 $this->draw_border = $draw_border;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
518
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
519 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
520 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
521
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
522 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
523 * Return draw border around QR Code.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
524 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
525 * @return bool
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
526 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
527 public function getDrawBorder()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
528 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
529 return $this->draw_border;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
530 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
531
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
532 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
533 * Set QR Code label (text).
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
534 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
535 * @param int|string $label Label to print under QR code
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
536 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
537 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
538 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
539 public function setLabel($label)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
540 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
541 $this->label = $label;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
542
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
543 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
544 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
545
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
546 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
547 * Return QR Code label (text).
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
548 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
549 * @return string
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
550 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
551 public function getLabel()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
552 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
553 return $this->label;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
554 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
555
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
556 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
557 * Set QR Code label font size.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
558 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
559 * @param int $label_font_size Font size of the QR code label
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
560 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
561 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
562 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
563 public function setLabelFontSize($label_font_size)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
564 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
565 $this->label_font_size = $label_font_size;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
566
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
567 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
568 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
569
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
570 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
571 * Return QR Code label font size.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
572 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
573 * @return int
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
574 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
575 public function getLabelFontSize()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
576 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
577 return $this->label_font_size;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
578 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
579
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
580 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
581 * Set QR Code label font path.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
582 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
583 * @param int $label_font_path Path to the QR Code label's TTF font file
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
584 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
585 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
586 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
587 public function setLabelFontPath($label_font_path)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
588 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
589 $this->label_font_path = $label_font_path;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
590
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
591 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
592 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
593
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
594 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
595 * Return path to the QR Code label's TTF font file.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
596 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
597 * @return string
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
598 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
599 public function getLabelFontPath()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
600 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
601 return $this->label_font_path;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
602 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
603
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
604 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
605 * Set label horizontal alignment.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
606 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
607 * @param int $label_halign Label horizontal alignment
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
608 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
609 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
610 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
611 public function setLabelHalign($label_halign)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
612 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
613 $this->label_halign = $label_halign;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
614
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
615 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
616 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
617
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
618 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
619 * Return label horizontal alignment.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
620 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
621 * @return int
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
622 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
623 public function getLabelHalign()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
624 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
625 return $this->label_halign;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
626 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
627
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
628 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
629 * Set label vertical alignment.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
630 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
631 * @param int $label_valign Label vertical alignment
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
632 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
633 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
634 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
635 public function setLabelValign($label_valign)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
636 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
637 $this->label_valign = $label_valign;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
638
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
639 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
640 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
641
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
642 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
643 * Return label vertical alignment.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
644 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
645 * @return int
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
646 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
647 public function getLabelValign()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
648 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
649 return $this->label_valign;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
650 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
651
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
652 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
653 * Set foreground color of the QR Code.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
654 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
655 * @param array $color_foreground RGB color
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
656 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
657 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
658 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
659 public function setForegroundColor($color_foreground)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
660 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
661 if (!isset($color_foreground['a'])) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
662 $color_foreground['a'] = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
663 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
664
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
665 $this->color_foreground = $color_foreground;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
666
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
667 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
668 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
669
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
670 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
671 * Return foreground color of the QR Code.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
672 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
673 * @return array
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
674 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
675 public function getForegroundColor()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
676 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
677 return $this->color_foreground;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
678 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
679
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
680 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
681 * Set background color of the QR Code.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
682 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
683 * @param array $color_background RGB color
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
684 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
685 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
686 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
687 public function setBackgroundColor($color_background)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
688 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
689 if (!isset($color_background['a'])) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
690 $color_background['a'] = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
691 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
692
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
693 $this->color_background = $color_background;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
694
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
695 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
696 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
697
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
698 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
699 * Return background color of the QR Code.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
700 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
701 * @return array
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
702 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
703 public function getBackgroundColor()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
704 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
705 return $this->color_background;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
706 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
707
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
708 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
709 * Return the image resource.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
710 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
711 * @return resource
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
712 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
713 public function getImage()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
714 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
715 if (empty($this->image)) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
716 $this->create();
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
717 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
718
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
719 return $this->image;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
720 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
721
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
722 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
723 * Return the data URI.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
724 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
725 * @return string
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
726 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
727 public function getDataUri()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
728 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
729 if (empty($this->image)) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
730 $this->create();
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
731 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
732
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
733 ob_start();
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
734 call_user_func('image'.$this->image_type, $this->image);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
735 $contents = ob_get_clean();
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
736
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
737 return 'data:image/'.$this->image_type.';base64,'.base64_encode($contents);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
738 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
739
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
740 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
741 * Render the QR Code then save it to given file name.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
742 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
743 * @param string $filename File name of the QR Code
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
744 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
745 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
746 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
747 public function save($filename)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
748 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
749 $this->render($filename);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
750
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
751 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
752 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
753
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
754 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
755 * Render the QR Code then save it to given file name or
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
756 * output it to the browser when file name omitted.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
757 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
758 * @param null|string $filename File name of the QR Code
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
759 * @param null|string $format Format of the file (png, jpeg, jpg, gif, wbmp)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
760 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
761 * @throws ImageFunctionUnknownException
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
762 * @throws ImageFunctionFailedException
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
763 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
764 * @return QrCode
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
765 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
766 public function render($filename = null, $format = 'png')
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
767 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
768 $this->create();
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
769
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
770 if ($format == 'jpg') {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
771 $format = 'jpeg';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
772 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
773
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
774 if (!in_array($format, $this->image_types_available)) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
775 $format = $this->image_type;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
776 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
777
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
778 if (!function_exists('image'.$format)) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
779 throw new ImageFunctionUnknownException('QRCode: function image'.$format.' does not exists.');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
780 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
781
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
782 if ($filename === null) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
783 $success = call_user_func('image'.$format, $this->image);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
784 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
785 $success = call_user_func_array('image'.$format, array($this->image, $filename));
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
786 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
787
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
788 if ($success === false) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
789 throw new ImageFunctionFailedException('QRCode: function image'.$format.' failed.');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
790 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
791
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
792 return $this;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
793 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
794
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
795 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
796 * Create QR Code and return its content.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
797 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
798 * @param string|null $format Image type (gif, png, wbmp, jpeg)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
799 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
800 * @throws ImageFunctionUnknownException
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
801 * @throws ImageFunctionFailedException
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
802 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
803 * @return string
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
804 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
805 public function get($format = null)
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
806 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
807 $this->create();
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
808
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
809 if ($format == 'jpg') {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
810 $format = 'jpeg';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
811 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
812
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
813 if (!in_array($format, $this->image_types_available)) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
814 $format = $this->image_type;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
815 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
816
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
817 if (!function_exists('image'.$format)) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
818 throw new ImageFunctionUnknownException('QRCode: function image'.$format.' does not exists.');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
819 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
820
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
821 ob_start();
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
822 $success = call_user_func('image'.$format, $this->image);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
823
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
824 if ($success === false) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
825 throw new ImageFunctionFailedException('QRCode: function image'.$format.' failed.');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
826 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
827
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
828 $content = ob_get_clean();
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
829
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
830 return $content;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
831 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
832
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
833 /**
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
834 * Create the image.
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
835 *
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
836 * @throws Exceptions\DataDoesntExistsException
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
837 * @throws Exceptions\VersionTooLargeException
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
838 * @throws Exceptions\ImageSizeTooLargeException
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
839 * @throws \OverflowException
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
840 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
841 public function create()
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
842 {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
843 $image_path = $this->image_path;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
844 $path = $this->path;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
845
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
846 $version_ul = 40;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
847
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
848 $qrcode_data_string = $this->text;//Previously from $_GET["d"];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
849
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
850 $qrcode_error_correct = $this->error_correction;//Previously from $_GET["e"];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
851 $qrcode_module_size = $this->module_size;//Previously from $_GET["s"];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
852 $qrcode_version = $this->version;//Previously from $_GET["v"];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
853 $qrcode_image_type = $this->image_type;//Previously from $_GET["t"];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
854
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
855 $qrcode_structureappend_n = $this->structure_append_n;//Previously from $_GET["n"];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
856 $qrcode_structureappend_m = $this->structure_append_m;//Previously from $_GET["m"];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
857 $qrcode_structureappend_parity = $this->structure_append_parity;//Previously from $_GET["p"];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
858 $qrcode_structureappend_originaldata = $this->structure_append_original_data;//Previously from $_GET["o"];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
859
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
860 if ($qrcode_module_size > 0) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
861 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
862 if ($qrcode_image_type == 'jpeg') {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
863 $qrcode_module_size = 8;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
864 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
865 $qrcode_module_size = 4;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
866 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
867 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
868 $data_length = strlen($qrcode_data_string);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
869 if ($data_length <= 0) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
870 throw new DataDoesntExistsException('QRCode: data does not exist.');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
871 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
872 $data_counter = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
873 if ($qrcode_structureappend_n > 1
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
874 && $qrcode_structureappend_n <= 16
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
875 && $qrcode_structureappend_m > 0
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
876 && $qrcode_structureappend_m <= 16) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
877 $data_value[0] = 3;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
878 $data_bits[0] = 4;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
879
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
880 $data_value[1] = $qrcode_structureappend_m - 1;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
881 $data_bits[1] = 4;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
882
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
883 $data_value[2] = $qrcode_structureappend_n - 1;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
884 $data_bits[2] = 4;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
885
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
886 $originaldata_length = strlen($qrcode_structureappend_originaldata);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
887 if ($originaldata_length > 1) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
888 $qrcode_structureappend_parity = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
889 $i = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
890 while ($i < $originaldata_length) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
891 $qrcode_structureappend_parity = ($qrcode_structureappend_parity ^ ord(substr($qrcode_structureappend_originaldata, $i, 1)));
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
892 ++$i;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
893 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
894 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
895
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
896 $data_value[3] = $qrcode_structureappend_parity;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
897 $data_bits[3] = 8;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
898
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
899 $data_counter = 4;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
900 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
901
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
902 $data_bits[$data_counter] = 4;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
903
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
904 /* --- determine encode mode */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
905
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
906 if (preg_match('/[^0-9]/', $qrcode_data_string) != 0) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
907 if (preg_match("/[^0-9A-Z \$\*\%\+\.\/\:\-]/", $qrcode_data_string) != 0) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
908 /* --- 8bit byte mode */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
909
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
910 $codeword_num_plus = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
911 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
912 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, );
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
913
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
914 $data_value[$data_counter] = 4;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
915 ++$data_counter;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
916 $data_value[$data_counter] = $data_length;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
917 $data_bits[$data_counter] = 8; /* #version 1-9 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
918 $codeword_num_counter_value = $data_counter;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
919
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
920 ++$data_counter;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
921 $i = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
922 while ($i < $data_length) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
923 $data_value[$data_counter] = ord(substr($qrcode_data_string, $i, 1));
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
924 $data_bits[$data_counter] = 8;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
925 ++$data_counter;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
926 ++$i;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
927 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
928 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
929 /* ---- alphanumeric mode */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
930
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
931 $codeword_num_plus = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
932 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
933 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, );
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
934
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
935 $data_value[$data_counter] = 2;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
936 ++$data_counter;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
937 $data_value[$data_counter] = $data_length;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
938 $data_bits[$data_counter] = 9; /* #version 1-9 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
939 $codeword_num_counter_value = $data_counter;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
940
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
941 $alphanumeric_character_hash = array('0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
942 '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, 'E' => 14,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
943 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, 'L' => 21, 'M' => 22, 'N' => 23,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
944 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
945 'W' => 32, 'X' => 33, 'Y' => 34, 'Z' => 35, ' ' => 36, '$' => 37, '%' => 38, '*' => 39,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
946 '+' => 40, '-' => 41, '.' => 42, '/' => 43, ':' => 44, );
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
947
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
948 $i = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
949 ++$data_counter;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
950 while ($i < $data_length) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
951 if (($i % 2) == 0) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
952 $data_value[$data_counter] = $alphanumeric_character_hash[substr($qrcode_data_string, $i, 1)];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
953 $data_bits[$data_counter] = 6;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
954 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
955 $data_value[$data_counter] = $data_value[$data_counter] * 45 + $alphanumeric_character_hash[substr($qrcode_data_string, $i, 1)];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
956 $data_bits[$data_counter] = 11;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
957 ++$data_counter;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
958 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
959 ++$i;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
960 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
961 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
962 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
963 /* ---- numeric mode */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
964
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
965 $codeword_num_plus = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
966 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
967 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, );
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
968
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
969 $data_value[$data_counter] = 1;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
970 ++$data_counter;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
971 $data_value[$data_counter] = $data_length;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
972 $data_bits[$data_counter] = 10; /* #version 1-9 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
973 $codeword_num_counter_value = $data_counter;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
974
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
975 $i = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
976 ++$data_counter;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
977 while ($i < $data_length) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
978 if (($i % 3) == 0) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
979 $data_value[$data_counter] = substr($qrcode_data_string, $i, 1);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
980 $data_bits[$data_counter] = 4;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
981 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
982 $data_value[$data_counter] = $data_value[$data_counter] * 10 + substr($qrcode_data_string, $i, 1);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
983 if (($i % 3) == 1) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
984 $data_bits[$data_counter] = 7;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
985 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
986 $data_bits[$data_counter] = 10;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
987 ++$data_counter;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
988 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
989 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
990 ++$i;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
991 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
992 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
993 if (array_key_exists($data_counter, $data_bits) && $data_bits[$data_counter] > 0) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
994 ++$data_counter;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
995 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
996 $i = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
997 $total_data_bits = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
998 while ($i < $data_counter) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
999 $total_data_bits += $data_bits[$i];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1000 ++$i;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1001 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1002
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1003 $ecc_character_hash = array('L' => '1',
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1004 'l' => '1',
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1005 'M' => '0',
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1006 'm' => '0',
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1007 'Q' => '3',
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1008 'q' => '3',
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1009 'H' => '2',
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1010 'h' => '2', );
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1011
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1012 if (!is_numeric($qrcode_error_correct)) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1013 $ec = @$ecc_character_hash[$qrcode_error_correct];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1014 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1015 $ec = $qrcode_error_correct;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1016 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1017
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1018 if (!$ec) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1019 $ec = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1020 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1021
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1022 $max_data_bits = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1023
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1024 $max_data_bits_array = array(
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1025 0, 128, 224, 352, 512, 688, 864, 992, 1232, 1456, 1728,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1026 2032, 2320, 2672, 2920, 3320, 3624, 4056, 4504, 5016, 5352,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1027 5712, 6256, 6880, 7312, 8000, 8496, 9024, 9544, 10136, 10984,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1028 11640, 12328, 13048, 13800, 14496, 15312, 15936, 16816, 17728, 18672,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1029
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1030 152, 272, 440, 640, 864, 1088, 1248, 1552, 1856, 2192,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1031 2592, 2960, 3424, 3688, 4184, 4712, 5176, 5768, 6360, 6888,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1032 7456, 8048, 8752, 9392, 10208, 10960, 11744, 12248, 13048, 13880,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1033 14744, 15640, 16568, 17528, 18448, 19472, 20528, 21616, 22496, 23648,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1034
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1035 72, 128, 208, 288, 368, 480, 528, 688, 800, 976,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1036 1120, 1264, 1440, 1576, 1784, 2024, 2264, 2504, 2728, 3080,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1037 3248, 3536, 3712, 4112, 4304, 4768, 5024, 5288, 5608, 5960,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1038 6344, 6760, 7208, 7688, 7888, 8432, 8768, 9136, 9776, 10208,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1039
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1040 104, 176, 272, 384, 496, 608, 704, 880, 1056, 1232,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1041 1440, 1648, 1952, 2088, 2360, 2600, 2936, 3176, 3560, 3880,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1042 4096, 4544, 4912, 5312, 5744, 6032, 6464, 6968, 7288, 7880,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1043 8264, 8920, 9368, 9848, 10288, 10832, 11408, 12016, 12656, 13328,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1044 );
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1045 if (!is_numeric($qrcode_version)) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1046 $qrcode_version = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1047 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1048 if (!$qrcode_version) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1049 /* #--- auto version select */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1050 $i = 1 + 40 * $ec;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1051 $j = $i + 39;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1052 $qrcode_version = 1;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1053 while ($i <= $j) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1054 if (($max_data_bits_array[$i]) >= $total_data_bits + $codeword_num_plus[$qrcode_version]) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1055 $max_data_bits = $max_data_bits_array[$i];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1056 break;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1057 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1058 ++$i;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1059 ++$qrcode_version;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1060 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1061 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1062 $max_data_bits = $max_data_bits_array[$qrcode_version + 40 * $ec];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1063 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1064 if ($qrcode_version > $version_ul) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1065 throw new VersionTooLargeException('QRCode : version too large');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1066 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1067
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1068 $total_data_bits += $codeword_num_plus[$qrcode_version];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1069 $data_bits[$codeword_num_counter_value] += $codeword_num_plus[$qrcode_version];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1070
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1071 $max_codewords_array = array(0, 26, 44, 70, 100, 134, 172, 196, 242,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1072 292, 346, 404, 466, 532, 581, 655, 733, 815, 901, 991, 1085, 1156,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1073 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185, 2323, 2465,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1074 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706, );
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1075
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1076 $max_codewords = $max_codewords_array[$qrcode_version];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1077 $max_modules_1side = 17 + ($qrcode_version << 2);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1078
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1079 $matrix_remain_bit = array(0, 0, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3,
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1080 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, );
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1081
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1082 /* ---- read version ECC data file */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1083
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1084 $byte_num = $matrix_remain_bit[$qrcode_version] + ($max_codewords << 3);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1085 $filename = $path.'/qrv'.$qrcode_version.'_'.$ec.'.dat';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1086 $fp1 = fopen($filename, 'rb');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1087 $matx = fread($fp1, $byte_num);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1088 $maty = fread($fp1, $byte_num);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1089 $masks = fread($fp1, $byte_num);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1090 $fi_x = fread($fp1, 15);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1091 $fi_y = fread($fp1, 15);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1092 $rs_ecc_codewords = ord(fread($fp1, 1));
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1093 $rso = fread($fp1, 128);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1094 fclose($fp1);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1095
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1096 $matrix_x_array = unpack('C*', $matx);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1097 $matrix_y_array = unpack('C*', $maty);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1098 $mask_array = unpack('C*', $masks);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1099
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1100 $rs_block_order = unpack('C*', $rso);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1101
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1102 $format_information_x2 = unpack('C*', $fi_x);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1103 $format_information_y2 = unpack('C*', $fi_y);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1104
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1105 $format_information_x1 = array(0, 1, 2, 3, 4, 5, 7, 8, 8, 8, 8, 8, 8, 8, 8);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1106 $format_information_y1 = array(8, 8, 8, 8, 8, 8, 8, 8, 7, 5, 4, 3, 2, 1, 0);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1107
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1108 $max_data_codewords = ($max_data_bits >> 3);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1109
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1110 $filename = $path.'/rsc'.$rs_ecc_codewords.'.dat';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1111 $fp0 = fopen($filename, 'rb');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1112 $i = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1113 $rs_cal_table_array = array();
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1114 while ($i < 256) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1115 $rs_cal_table_array[$i] = fread($fp0, $rs_ecc_codewords);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1116 ++$i;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1117 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1118 fclose($fp0);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1119
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1120 /* --- set terminator */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1121
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1122 if ($total_data_bits <= $max_data_bits - 4) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1123 $data_value[$data_counter] = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1124 $data_bits[$data_counter] = 4;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1125 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1126 if ($total_data_bits < $max_data_bits) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1127 $data_value[$data_counter] = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1128 $data_bits[$data_counter] = $max_data_bits - $total_data_bits;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1129 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1130 if ($total_data_bits > $max_data_bits) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1131 throw new \OverflowException('QRCode: overflow error');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1132 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1133 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1134 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1135
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1136 /* ----divide data by 8bit */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1137
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1138 $i = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1139 $codewords_counter = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1140 $codewords[0] = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1141 $remaining_bits = 8;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1142
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1143 while ($i <= $data_counter) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1144 $buffer = @$data_value[$i];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1145 $buffer_bits = @$data_bits[$i];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1146
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1147 $flag = 1;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1148 while ($flag) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1149 if ($remaining_bits > $buffer_bits) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1150 $codewords[$codewords_counter] = ((@$codewords[$codewords_counter] << $buffer_bits) | $buffer);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1151 $remaining_bits -= $buffer_bits;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1152 $flag = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1153 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1154 $buffer_bits -= $remaining_bits;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1155 $codewords[$codewords_counter] = (($codewords[$codewords_counter] << $remaining_bits) | ($buffer >> $buffer_bits));
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1156
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1157 if ($buffer_bits == 0) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1158 $flag = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1159 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1160 $buffer = ($buffer & ((1 << $buffer_bits) - 1));
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1161 $flag = 1;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1162 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1163
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1164 ++$codewords_counter;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1165 if ($codewords_counter < $max_data_codewords - 1) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1166 $codewords[$codewords_counter] = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1167 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1168 $remaining_bits = 8;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1169 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1170 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1171 ++$i;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1172 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1173 if ($remaining_bits != 8) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1174 $codewords[$codewords_counter] = $codewords[$codewords_counter] << $remaining_bits;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1175 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1176 --$codewords_counter;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1177 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1178
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1179 /* ---- set padding character */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1180
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1181 if ($codewords_counter < $max_data_codewords - 1) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1182 $flag = 1;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1183 while ($codewords_counter < $max_data_codewords - 1) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1184 ++$codewords_counter;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1185 if ($flag == 1) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1186 $codewords[$codewords_counter] = 236;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1187 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1188 $codewords[$codewords_counter] = 17;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1189 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1190 $flag = $flag * (-1);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1191 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1192 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1193
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1194 /* ---- RS-ECC prepare */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1195
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1196 $i = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1197 $j = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1198 $rs_block_number = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1199 $rs_temp[0] = '';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1200
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1201 while ($i < $max_data_codewords) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1202 $rs_temp[$rs_block_number] .= chr($codewords[$i]);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1203 ++$j;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1204
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1205 if ($j >= $rs_block_order[$rs_block_number + 1] - $rs_ecc_codewords) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1206 $j = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1207 ++$rs_block_number;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1208 $rs_temp[$rs_block_number] = '';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1209 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1210 ++$i;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1211 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1212
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1213 /*
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1214 #
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1215 # RS-ECC main
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1216 #
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1217 */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1218
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1219 $rs_block_number = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1220 $rs_block_order_num = count($rs_block_order);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1221
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1222 while ($rs_block_number < $rs_block_order_num) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1223 $rs_codewords = $rs_block_order[$rs_block_number + 1];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1224 $rs_data_codewords = $rs_codewords - $rs_ecc_codewords;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1225
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1226 $rstemp = $rs_temp[$rs_block_number].str_repeat(chr(0), $rs_ecc_codewords);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1227 $padding_data = str_repeat(chr(0), $rs_data_codewords);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1228
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1229 $j = $rs_data_codewords;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1230 while ($j > 0) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1231 $first = ord(substr($rstemp, 0, 1));
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1232
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1233 if ($first) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1234 $left_chr = substr($rstemp, 1);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1235 $cal = $rs_cal_table_array[$first].$padding_data;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1236 $rstemp = $left_chr ^ $cal;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1237 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1238 $rstemp = substr($rstemp, 1);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1239 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1240
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1241 --$j;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1242 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1243
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1244 $codewords = array_merge($codewords, unpack('C*', $rstemp));
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1245
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1246 ++$rs_block_number;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1247 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1248
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1249 /* ---- flash matrix */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1250 $matrix_content = array();
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1251 $i = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1252 while ($i < $max_modules_1side) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1253 $j = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1254 while ($j < $max_modules_1side) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1255 $matrix_content[$j][$i] = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1256 ++$j;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1257 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1258 ++$i;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1259 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1260
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1261 /* --- attach data */
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1262
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1263 $i = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1264 while ($i < $max_codewords) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1265 $codeword_i = $codewords[$i];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1266 $j = 8;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1267 while ($j >= 1) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1268 $codeword_bits_number = ($i << 3) + $j;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1269 $matrix_content[ $matrix_x_array[$codeword_bits_number] ][ $matrix_y_array[$codeword_bits_number] ] = ((255 * ($codeword_i & 1)) ^ $mask_array[$codeword_bits_number]);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1270 $codeword_i = $codeword_i >> 1;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1271 --$j;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1272 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1273 ++$i;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1274 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1275
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1276 $matrix_remain = $matrix_remain_bit[$qrcode_version];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1277 while ($matrix_remain) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1278 $remain_bit_temp = $matrix_remain + ($max_codewords << 3);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1279 $matrix_content[ $matrix_x_array[$remain_bit_temp] ][ $matrix_y_array[$remain_bit_temp] ] = (255 ^ $mask_array[$remain_bit_temp]);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1280 --$matrix_remain;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1281 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1282
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1283 #--- mask select
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1284
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1285 $min_demerit_score = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1286 $hor_master = '';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1287 $ver_master = '';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1288 $k = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1289 while ($k < $max_modules_1side) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1290 $l = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1291 while ($l < $max_modules_1side) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1292 $hor_master = $hor_master.chr($matrix_content[$l][$k]);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1293 $ver_master = $ver_master.chr($matrix_content[$k][$l]);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1294 ++$l;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1295 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1296 ++$k;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1297 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1298 $i = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1299 $all_matrix = $max_modules_1side * $max_modules_1side;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1300 $mask_number = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1301 while ($i < 8) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1302 $demerit_n1 = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1303 $ptn_temp = array();
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1304 $bit = 1 << $i;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1305 $bit_r = (~$bit) & 255;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1306 $bit_mask = str_repeat(chr($bit), $all_matrix);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1307 $hor = $hor_master & $bit_mask;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1308 $ver = $ver_master & $bit_mask;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1309
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1310 $ver_shift1 = $ver.str_repeat(chr(170), $max_modules_1side);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1311 $ver_shift2 = str_repeat(chr(170), $max_modules_1side).$ver;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1312 $ver_shift1_0 = $ver.str_repeat(chr(0), $max_modules_1side);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1313 $ver_shift2_0 = str_repeat(chr(0), $max_modules_1side).$ver;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1314 $ver_or = chunk_split(~($ver_shift1 | $ver_shift2), $max_modules_1side, chr(170));
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1315 $ver_and = chunk_split(~($ver_shift1_0 & $ver_shift2_0), $max_modules_1side, chr(170));
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1316
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1317 $hor = chunk_split(~$hor, $max_modules_1side, chr(170));
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1318 $ver = chunk_split(~$ver, $max_modules_1side, chr(170));
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1319 $hor = $hor.chr(170).$ver;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1320
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1321 $n1_search = '/'.str_repeat(chr(255), 5).'+|'.str_repeat(chr($bit_r), 5).'+/';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1322 $n3_search = chr($bit_r).chr(255).chr($bit_r).chr($bit_r).chr($bit_r).chr(255).chr($bit_r);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1323
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1324 $demerit_n3 = substr_count($hor, $n3_search) * 40;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1325 $demerit_n4 = floor(abs(((100 * (substr_count($ver, chr($bit_r)) / ($byte_num))) - 50) / 5)) * 10;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1326
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1327 $n2_search1 = '/'.chr($bit_r).chr($bit_r).'+/';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1328 $n2_search2 = '/'.chr(255).chr(255).'+/';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1329 $demerit_n2 = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1330 preg_match_all($n2_search1, $ver_and, $ptn_temp);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1331 foreach ($ptn_temp[0] as $str_temp) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1332 $demerit_n2 += (strlen($str_temp) - 1);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1333 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1334 $ptn_temp = array();
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1335 preg_match_all($n2_search2, $ver_or, $ptn_temp);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1336 foreach ($ptn_temp[0] as $str_temp) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1337 $demerit_n2 += (strlen($str_temp) - 1);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1338 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1339 $demerit_n2 *= 3;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1340
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1341 $ptn_temp = array();
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1342
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1343 preg_match_all($n1_search, $hor, $ptn_temp);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1344 foreach ($ptn_temp[0] as $str_temp) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1345 $demerit_n1 += (strlen($str_temp) - 2);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1346 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1347
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1348 $demerit_score = $demerit_n1 + $demerit_n2 + $demerit_n3 + $demerit_n4;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1349
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1350 if ($demerit_score <= $min_demerit_score || $i == 0) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1351 $mask_number = $i;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1352 $min_demerit_score = $demerit_score;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1353 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1354
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1355 ++$i;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1356 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1357
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1358 $mask_content = 1 << $mask_number;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1359
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1360 # --- format information
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1361
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1362 $format_information_value = (($ec << 3) | $mask_number);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1363 $format_information_array = array('101010000010010', '101000100100101',
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1364 '101111001111100', '101101101001011', '100010111111001', '100000011001110',
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1365 '100111110010111', '100101010100000', '111011111000100', '111001011110011',
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1366 '111110110101010', '111100010011101', '110011000101111', '110001100011000',
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1367 '110110001000001', '110100101110110', '001011010001001', '001001110111110',
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1368 '001110011100111', '001100111010000', '000011101100010', '000001001010101',
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1369 '000110100001100', '000100000111011', '011010101011111', '011000001101000',
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1370 '011111100110001', '011101000000110', '010010010110100', '010000110000011',
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1371 '010111011011010', '010101111101101', );
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1372 $i = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1373 while ($i < 15) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1374 $content = substr($format_information_array[$format_information_value], $i, 1);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1375
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1376 $matrix_content[$format_information_x1[$i]][$format_information_y1[$i]] = $content * 255;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1377 $matrix_content[$format_information_x2[$i + 1]][$format_information_y2[$i + 1]] = $content * 255;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1378 ++$i;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1379 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1380
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1381 $mib = $max_modules_1side + 8;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1382
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1383 if ($this->size == 0) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1384 $this->size = $mib * $qrcode_module_size;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1385 if ($this->size > 1480) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1386 throw new ImageSizeTooLargeException('QRCode: image size too large');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1387 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1388 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1389
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1390 $image_width = $this->size + $this->padding * 2;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1391 $image_height = $this->size + $this->padding * 2;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1392
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1393 if (!empty($this->label)) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1394 if (!function_exists('imagettfbbox')) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1395 throw new FreeTypeLibraryMissingException('QRCode: missing function "imagettfbbox". Did you install the FreeType library?');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1396 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1397 $font_box = imagettfbbox($this->label_font_size, 0, $this->label_font_path, $this->label);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1398 $label_width = (int) $font_box[2] - (int) $font_box[0];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1399 $label_height = (int) $font_box[0] - (int) $font_box[7];
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1400
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1401 if ($this->label_valign == self::LABEL_VALIGN_MIDDLE) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1402 $image_height += $label_height + $this->padding;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1403 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1404 $image_height += $label_height;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1405 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1406 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1407
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1408 $output_image = imagecreate($image_width, $image_height);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1409 imagecolorallocate($output_image, 255, 255, 255);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1410
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1411 $image_path = $image_path.'/qrv'.$qrcode_version.'.png';
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1412
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1413 $base_image = imagecreatefrompng($image_path);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1414 $code_size = $this->size;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1415 $module_size = function ($size = 1) use ($code_size, $base_image) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1416 return round($code_size / imagesx($base_image) * $size);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1417 };
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1418
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1419 $col[1] = imagecolorallocate($base_image, 0, 0, 0);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1420 $col[0] = imagecolorallocate($base_image, 255, 255, 255);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1421
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1422 $i = 4;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1423 $mxe = 4 + $max_modules_1side;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1424 $ii = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1425 while ($i < $mxe) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1426 $j = 4;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1427 $jj = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1428 while ($j < $mxe) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1429 if ($matrix_content[$ii][$jj] & $mask_content) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1430 imagesetpixel($base_image, $i, $j, $col[1]);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1431 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1432 ++$j;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1433 ++$jj;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1434 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1435 ++$i;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1436 ++$ii;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1437 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1438
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1439 if ($this->draw_quiet_zone == true) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1440 imagecopyresampled($output_image, $base_image, $this->padding, $this->padding, 0, 0, $this->size, $this->size, $mib, $mib);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1441 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1442 imagecopyresampled($output_image, $base_image, $this->padding, $this->padding, 4, 4, $this->size, $this->size, $mib - 8, $mib - 8);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1443 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1444
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1445 if ($this->draw_border == true) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1446 $border_width = $this->padding;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1447 $border_height = $this->size + $this->padding - 1;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1448 $border_color = imagecolorallocate($output_image, 0, 0, 0);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1449 imagerectangle($output_image, $border_width, $border_width, $border_height, $border_height, $border_color);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1450 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1451
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1452 if (!empty($this->label)) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1453 // Label horizontal alignment
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1454 switch ($this->label_halign) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1455 case self::LABEL_HALIGN_LEFT:
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1456 $font_x = 0;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1457 break;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1458
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1459 case self::LABEL_HALIGN_LEFT_BORDER:
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1460 $font_x = $this->padding;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1461 break;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1462
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1463 case self::LABEL_HALIGN_LEFT_CODE:
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1464 if ($this->draw_quiet_zone == true) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1465 $font_x = $this->padding + $module_size(4);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1466 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1467 $font_x = $this->padding;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1468 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1469 break;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1470
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1471 case self::LABEL_HALIGN_RIGHT:
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1472 $font_x = $this->size + ($this->padding * 2) - $label_width;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1473 break;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1474
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1475 case self::LABEL_HALIGN_RIGHT_BORDER:
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1476 $font_x = $this->size + $this->padding - $label_width;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1477 break;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1478
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1479 case self::LABEL_HALIGN_RIGHT_CODE:
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1480 if ($this->draw_quiet_zone == true) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1481 $font_x = $this->size + $this->padding - $label_width - $module_size(4);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1482 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1483 $font_x = $this->size + $this->padding - $label_width;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1484 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1485 break;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1486
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1487 default:
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1488 $font_x = floor($image_width - $label_width) / 2;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1489 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1490
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1491 // Label vertical alignment
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1492 switch ($this->label_valign) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1493 case self::LABEL_VALIGN_TOP_NO_BORDER:
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1494 $font_y = $image_height - $this->padding - 1;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1495 break;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1496
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1497 case self::LABEL_VALIGN_BOTTOM:
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1498 $font_y = $image_height;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1499 break;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1500
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1501 default:
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1502 $font_y = $image_height - $this->padding;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1503 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1504
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1505 $label_bg_x1 = $font_x - $module_size(2);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1506 $label_bg_y1 = $font_y - $label_height;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1507 $label_bg_x2 = $font_x + $label_width + $module_size(2);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1508 $label_bg_y2 = $font_y;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1509
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1510 $color = imagecolorallocate($output_image, 0, 0, 0);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1511 $label_bg_color = imagecolorallocate($output_image, 255, 255, 255);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1512
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1513 imagefilledrectangle($output_image, $label_bg_x1, $label_bg_y1, $label_bg_x2, $label_bg_y2, $label_bg_color);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1514 imagettftext($output_image, $this->label_font_size, 0, $font_x, $font_y, $color, $this->label_font_path, $this->label);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1515 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1516
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1517 $imagecolorset_function = new ReflectionFunction('imagecolorset');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1518 $allow_alpha = $imagecolorset_function->getNumberOfParameters() == 6;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1519
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1520 if ($this->color_background != null) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1521 $index = imagecolorclosest($output_image, 255, 255, 255);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1522 if ($allow_alpha) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1523 imagecolorset($output_image, $index, $this->color_background['r'], $this->color_background['g'], $this->color_background['b'], $this->color_background['a']);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1524 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1525 imagecolorset($output_image, $index, $this->color_background['r'], $this->color_background['g'], $this->color_background['b']);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1526 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1527 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1528
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1529 if ($this->color_foreground != null) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1530 $index = imagecolorclosest($output_image, 0, 0, 0);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1531 if ($allow_alpha) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1532 imagecolorset($output_image, $index, $this->color_foreground['r'], $this->color_foreground['g'], $this->color_foreground['b'], $this->color_foreground['a']);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1533 } else {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1534 imagecolorset($output_image, $index, $this->color_foreground['r'], $this->color_foreground['g'], $this->color_foreground['b']);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1535 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1536 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1537
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1538 if (!empty($this->logo)) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1539 $output_image_org = $output_image;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1540 $output_image = imagecreatetruecolor($image_width, $image_height);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1541 imagecopy($output_image, $output_image_org, 0, 0, 0, 0, $image_width, $image_height);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1542
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1543 $logo_image = call_user_func('imagecreatefrom'.$this->image_type, $this->logo);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1544 if (!$logo_image) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1545 throw new ImageFunctionFailedException('imagecreatefrom'.$this->image_type.' '.$this->logo.' failed');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1546 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1547 $src_w = imagesx($logo_image);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1548 $src_h = imagesy($logo_image);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1549
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1550 $dst_x = ($image_width - $this->logo_size) / 2;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1551 $dst_y = ($this->size + $this->padding * 2 - $this->logo_size) / 2;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1552
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1553 $successful = imagecopyresampled($output_image, $logo_image, $dst_x, $dst_y, 0, 0, $this->logo_size, $this->logo_size, $src_w, $src_h);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1554 if (!$successful) {
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1555 throw new ImageFunctionFailedException('add logo [image'.$this->format.'] failed.');
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1556 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1557 imagedestroy($logo_image);
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1558 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1559 $this->image = $output_image;
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1560 }
cec75ba50afc endroid/qrcode as distributed
Charlie Root
parents:
diff changeset
1561 }