PageRenderTime 61ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/src/libs/qrcode/phpqrcode.php

https://github.com/mips-lab/jetons
PHP | 3609 lines | 2340 code | 731 blank | 538 comment | 436 complexity | d91dbc28755d36a008319ff9340f83ce MD5 | raw file
Possible License(s): LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. * PHP QR Code encoder
  4. *
  5. * This file contains MERGED version of PHP QR Code library.
  6. * It was auto-generated from full version for your convenience.
  7. *
  8. * This merged version was configured to not require any external files,
  9. * with disabled cache, error logging and weaker but faster mask matching.
  10. * If you need tune it up please use non-merged version.
  11. *
  12. * For full version, documentation, examples of use please visit:
  13. *
  14. * http://phpqrcode.sourceforge.net/
  15. * https://sourceforge.net/projects/phpqrcode/
  16. * https://github.com/t0k4rt/phpqrcode
  17. *
  18. * PHP QR Code is distributed under LGPL 3
  19. * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
  20. *
  21. * This library is free software; you can redistribute it and/or
  22. * modify it under the terms of the GNU Lesser General Public
  23. * License as published by the Free Software Foundation; either
  24. * version 3 of the License, or any later version.
  25. *
  26. * This library is distributed in the hope that it will be useful,
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  29. * Lesser General Public License for more details.
  30. *
  31. * You should have received a copy of the GNU Lesser General Public
  32. * License along with this library; if not, write to the Free Software
  33. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  34. */
  35. /*
  36. * Version: 1.1.4
  37. * Build: 2010100721
  38. */
  39. //---- qrconst.php -----------------------------
  40. /*
  41. * PHP QR Code encoder
  42. *
  43. * Common constants
  44. *
  45. * Based on libqrencode C library distributed under LGPL 2.1
  46. * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
  47. *
  48. * PHP QR Code is distributed under LGPL 3
  49. * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
  50. *
  51. * This library is free software; you can redistribute it and/or
  52. * modify it under the terms of the GNU Lesser General Public
  53. * License as published by the Free Software Foundation; either
  54. * version 3 of the License, or any later version.
  55. *
  56. * This library is distributed in the hope that it will be useful,
  57. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  58. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  59. * Lesser General Public License for more details.
  60. *
  61. * You should have received a copy of the GNU Lesser General Public
  62. * License along with this library; if not, write to the Free Software
  63. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  64. */
  65. // Encoding modes
  66. define('QR_MODE_NUL', -1);
  67. define('QR_MODE_NUM', 0);
  68. define('QR_MODE_AN', 1);
  69. define('QR_MODE_8', 2);
  70. define('QR_MODE_KANJI', 3);
  71. define('QR_MODE_STRUCTURE', 4);
  72. // Levels of error correction.
  73. define('QR_ECLEVEL_L', 0);
  74. define('QR_ECLEVEL_M', 1);
  75. define('QR_ECLEVEL_Q', 2);
  76. define('QR_ECLEVEL_H', 3);
  77. // Supported output formats
  78. define('QR_FORMAT_TEXT', 0);
  79. define('QR_FORMAT_PNG', 1);
  80. class qrstr {
  81. public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
  82. $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl));
  83. }
  84. }
  85. //---- merged_config.php -----------------------------
  86. /*
  87. * PHP QR Code encoder
  88. *
  89. * Config file, tuned-up for merged verion
  90. */
  91. define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there
  92. define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true
  93. define('QR_LOG_DIR', false); // default error logs dir
  94. define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code
  95. define('QR_FIND_FROM_RANDOM', 2); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly
  96. define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
  97. define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images
  98. //---- qrtools.php -----------------------------
  99. /*
  100. * PHP QR Code encoder
  101. *
  102. * Toolset, handy and debug utilites.
  103. *
  104. * PHP QR Code is distributed under LGPL 3
  105. * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
  106. *
  107. * This library is free software; you can redistribute it and/or
  108. * modify it under the terms of the GNU Lesser General Public
  109. * License as published by the Free Software Foundation; either
  110. * version 3 of the License, or any later version.
  111. *
  112. * This library is distributed in the hope that it will be useful,
  113. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  114. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  115. * Lesser General Public License for more details.
  116. *
  117. * You should have received a copy of the GNU Lesser General Public
  118. * License along with this library; if not, write to the Free Software
  119. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  120. */
  121. class QRtools {
  122. //----------------------------------------------------------------------
  123. public static function binarize($frame)
  124. {
  125. $len = count($frame);
  126. foreach ($frame as &$frameLine) {
  127. for($i=0; $i<$len; $i++) {
  128. $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
  129. }
  130. }
  131. return $frame;
  132. }
  133. //----------------------------------------------------------------------
  134. public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037')
  135. {
  136. $barcode_array = array();
  137. if (!is_array($mode))
  138. $mode = explode(',', $mode);
  139. $eccLevel = 'L';
  140. if (count($mode) > 1) {
  141. $eccLevel = $mode[1];
  142. }
  143. $qrTab = QRcode::text($code, false, $eccLevel);
  144. $size = count($qrTab);
  145. $barcode_array['num_rows'] = $size;
  146. $barcode_array['num_cols'] = $size;
  147. $barcode_array['bcode'] = array();
  148. foreach ($qrTab as $line) {
  149. $arrAdd = array();
  150. foreach(str_split($line) as $char)
  151. $arrAdd[] = ($char=='1')?1:0;
  152. $barcode_array['bcode'][] = $arrAdd;
  153. }
  154. return $barcode_array;
  155. }
  156. //----------------------------------------------------------------------
  157. public static function clearCache()
  158. {
  159. self::$frames = array();
  160. }
  161. //----------------------------------------------------------------------
  162. public static function buildCache()
  163. {
  164. QRtools::markTime('before_build_cache');
  165. $mask = new QRmask();
  166. for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
  167. $frame = QRspec::newFrame($a);
  168. if (QR_IMAGE) {
  169. $fileName = QR_CACHE_DIR.'frame_'.$a.'.png';
  170. QRimage::png(self::binarize($frame), $fileName, 1, 0);
  171. }
  172. $width = count($frame);
  173. $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
  174. for ($maskNo=0; $maskNo<8; $maskNo++)
  175. $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
  176. }
  177. QRtools::markTime('after_build_cache');
  178. }
  179. //----------------------------------------------------------------------
  180. public static function log($outfile, $err)
  181. {
  182. if (QR_LOG_DIR !== false) {
  183. if ($err != '') {
  184. if ($outfile !== false) {
  185. file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
  186. } else {
  187. file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
  188. }
  189. }
  190. }
  191. }
  192. //----------------------------------------------------------------------
  193. public static function dumpMask($frame)
  194. {
  195. $width = count($frame);
  196. for($y=0;$y<$width;$y++) {
  197. for($x=0;$x<$width;$x++) {
  198. echo ord($frame[$y][$x]).',';
  199. }
  200. }
  201. }
  202. //----------------------------------------------------------------------
  203. public static function markTime($markerId)
  204. {
  205. list($usec, $sec) = explode(" ", microtime());
  206. $time = ((float)$usec + (float)$sec);
  207. if (!isset($GLOBALS['qr_time_bench']))
  208. $GLOBALS['qr_time_bench'] = array();
  209. $GLOBALS['qr_time_bench'][$markerId] = $time;
  210. }
  211. //----------------------------------------------------------------------
  212. public static function timeBenchmark()
  213. {
  214. self::markTime('finish');
  215. $lastTime = 0;
  216. $startTime = 0;
  217. $p = 0;
  218. echo '<table cellpadding="3" cellspacing="1">
  219. <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead>
  220. <tbody>';
  221. foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
  222. if ($p > 0) {
  223. echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>';
  224. } else {
  225. $startTime = $thisTime;
  226. }
  227. $p++;
  228. $lastTime = $thisTime;
  229. }
  230. echo '</tbody><tfoot>
  231. <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr>
  232. </tfoot>
  233. </table>';
  234. }
  235. public static function save($content, $filename_path)
  236. {
  237. try {
  238. $handle = fopen($filename_path, "w");
  239. fwrite($handle, $content);
  240. fclose($handle);
  241. return true;
  242. } catch (Exception $e) {
  243. echo 'Exception reรงue : ', $e->getMessage(), "\n";
  244. }
  245. }
  246. }
  247. //##########################################################################
  248. QRtools::markTime('start');
  249. //---- qrspec.php -----------------------------
  250. /*
  251. * PHP QR Code encoder
  252. *
  253. * QR Code specifications
  254. *
  255. * Based on libqrencode C library distributed under LGPL 2.1
  256. * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
  257. *
  258. * PHP QR Code is distributed under LGPL 3
  259. * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
  260. *
  261. * The following data / specifications are taken from
  262. * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004)
  263. * or
  264. * "Automatic identification and data capture techniques --
  265. * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006)
  266. *
  267. * This library is free software; you can redistribute it and/or
  268. * modify it under the terms of the GNU Lesser General Public
  269. * License as published by the Free Software Foundation; either
  270. * version 3 of the License, or any later version.
  271. *
  272. * This library is distributed in the hope that it will be useful,
  273. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  274. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  275. * Lesser General Public License for more details.
  276. *
  277. * You should have received a copy of the GNU Lesser General Public
  278. * License along with this library; if not, write to the Free Software
  279. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  280. */
  281. define('QRSPEC_VERSION_MAX', 40);
  282. define('QRSPEC_WIDTH_MAX', 177);
  283. define('QRCAP_WIDTH', 0);
  284. define('QRCAP_WORDS', 1);
  285. define('QRCAP_REMINDER', 2);
  286. define('QRCAP_EC', 3);
  287. class QRspec {
  288. public static $capacity = array(
  289. array( 0, 0, 0, array( 0, 0, 0, 0)),
  290. array( 21, 26, 0, array( 7, 10, 13, 17)), // 1
  291. array( 25, 44, 7, array( 10, 16, 22, 28)),
  292. array( 29, 70, 7, array( 15, 26, 36, 44)),
  293. array( 33, 100, 7, array( 20, 36, 52, 64)),
  294. array( 37, 134, 7, array( 26, 48, 72, 88)), // 5
  295. array( 41, 172, 7, array( 36, 64, 96, 112)),
  296. array( 45, 196, 0, array( 40, 72, 108, 130)),
  297. array( 49, 242, 0, array( 48, 88, 132, 156)),
  298. array( 53, 292, 0, array( 60, 110, 160, 192)),
  299. array( 57, 346, 0, array( 72, 130, 192, 224)), //10
  300. array( 61, 404, 0, array( 80, 150, 224, 264)),
  301. array( 65, 466, 0, array( 96, 176, 260, 308)),
  302. array( 69, 532, 0, array( 104, 198, 288, 352)),
  303. array( 73, 581, 3, array( 120, 216, 320, 384)),
  304. array( 77, 655, 3, array( 132, 240, 360, 432)), //15
  305. array( 81, 733, 3, array( 144, 280, 408, 480)),
  306. array( 85, 815, 3, array( 168, 308, 448, 532)),
  307. array( 89, 901, 3, array( 180, 338, 504, 588)),
  308. array( 93, 991, 3, array( 196, 364, 546, 650)),
  309. array( 97, 1085, 3, array( 224, 416, 600, 700)), //20
  310. array(101, 1156, 4, array( 224, 442, 644, 750)),
  311. array(105, 1258, 4, array( 252, 476, 690, 816)),
  312. array(109, 1364, 4, array( 270, 504, 750, 900)),
  313. array(113, 1474, 4, array( 300, 560, 810, 960)),
  314. array(117, 1588, 4, array( 312, 588, 870, 1050)), //25
  315. array(121, 1706, 4, array( 336, 644, 952, 1110)),
  316. array(125, 1828, 4, array( 360, 700, 1020, 1200)),
  317. array(129, 1921, 3, array( 390, 728, 1050, 1260)),
  318. array(133, 2051, 3, array( 420, 784, 1140, 1350)),
  319. array(137, 2185, 3, array( 450, 812, 1200, 1440)), //30
  320. array(141, 2323, 3, array( 480, 868, 1290, 1530)),
  321. array(145, 2465, 3, array( 510, 924, 1350, 1620)),
  322. array(149, 2611, 3, array( 540, 980, 1440, 1710)),
  323. array(153, 2761, 3, array( 570, 1036, 1530, 1800)),
  324. array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35
  325. array(161, 3034, 0, array( 600, 1120, 1680, 1980)),
  326. array(165, 3196, 0, array( 630, 1204, 1770, 2100)),
  327. array(169, 3362, 0, array( 660, 1260, 1860, 2220)),
  328. array(173, 3532, 0, array( 720, 1316, 1950, 2310)),
  329. array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40
  330. );
  331. //----------------------------------------------------------------------
  332. public static function getDataLength($version, $level)
  333. {
  334. return self::$capacity[$version][QRCAP_WORDS] - self::$capacity[$version][QRCAP_EC][$level];
  335. }
  336. //----------------------------------------------------------------------
  337. public static function getECCLength($version, $level)
  338. {
  339. return self::$capacity[$version][QRCAP_EC][$level];
  340. }
  341. //----------------------------------------------------------------------
  342. public static function getWidth($version)
  343. {
  344. return self::$capacity[$version][QRCAP_WIDTH];
  345. }
  346. //----------------------------------------------------------------------
  347. public static function getRemainder($version)
  348. {
  349. return self::$capacity[$version][QRCAP_REMINDER];
  350. }
  351. //----------------------------------------------------------------------
  352. public static function getMinimumVersion($size, $level)
  353. {
  354. for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
  355. $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level];
  356. if($words >= $size)
  357. return $i;
  358. }
  359. return -1;
  360. }
  361. //######################################################################
  362. public static $lengthTableBits = array(
  363. array(10, 12, 14),
  364. array( 9, 11, 13),
  365. array( 8, 16, 16),
  366. array( 8, 10, 12)
  367. );
  368. //----------------------------------------------------------------------
  369. public static function lengthIndicator($mode, $version)
  370. {
  371. if ($mode == QR_MODE_STRUCTURE)
  372. return 0;
  373. if ($version <= 9) {
  374. $l = 0;
  375. } else if ($version <= 26) {
  376. $l = 1;
  377. } else {
  378. $l = 2;
  379. }
  380. return self::$lengthTableBits[$mode][$l];
  381. }
  382. //----------------------------------------------------------------------
  383. public static function maximumWords($mode, $version)
  384. {
  385. if($mode == QR_MODE_STRUCTURE)
  386. return 3;
  387. if($version <= 9) {
  388. $l = 0;
  389. } else if($version <= 26) {
  390. $l = 1;
  391. } else {
  392. $l = 2;
  393. }
  394. $bits = self::$lengthTableBits[$mode][$l];
  395. $words = (1 << $bits) - 1;
  396. if($mode == QR_MODE_KANJI) {
  397. $words *= 2; // the number of bytes is required
  398. }
  399. return $words;
  400. }
  401. // Error correction code -----------------------------------------------
  402. // Table of the error correction code (Reed-Solomon block)
  403. // See Table 12-16 (pp.30-36), JIS X0510:2004.
  404. public static $eccTable = array(
  405. array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)),
  406. array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1
  407. array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)),
  408. array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)),
  409. array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)),
  410. array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5
  411. array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)),
  412. array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)),
  413. array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)),
  414. array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)),
  415. array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), //10
  416. array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)),
  417. array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)),
  418. array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)),
  419. array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)),
  420. array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), //15
  421. array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)),
  422. array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)),
  423. array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)),
  424. array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)),
  425. array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), //20
  426. array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)),
  427. array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)),
  428. array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)),
  429. array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)),
  430. array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), //25
  431. array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)),
  432. array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)),
  433. array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)),
  434. array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)),
  435. array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30
  436. array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)),
  437. array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)),
  438. array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)),
  439. array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)),
  440. array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), //35
  441. array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)),
  442. array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)),
  443. array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)),
  444. array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)),
  445. array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)),//40
  446. );
  447. //----------------------------------------------------------------------
  448. // CACHEABLE!!!
  449. public static function getEccSpec($version, $level, array &$spec)
  450. {
  451. if (count($spec) < 5) {
  452. $spec = array(0,0,0,0,0);
  453. }
  454. $b1 = self::$eccTable[$version][$level][0];
  455. $b2 = self::$eccTable[$version][$level][1];
  456. $data = self::getDataLength($version, $level);
  457. $ecc = self::getECCLength($version, $level);
  458. if($b2 == 0) {
  459. $spec[0] = $b1;
  460. $spec[1] = (int)($data / $b1);
  461. $spec[2] = (int)($ecc / $b1);
  462. $spec[3] = 0;
  463. $spec[4] = 0;
  464. } else {
  465. $spec[0] = $b1;
  466. $spec[1] = (int)($data / ($b1 + $b2));
  467. $spec[2] = (int)($ecc / ($b1 + $b2));
  468. $spec[3] = $b2;
  469. $spec[4] = $spec[1] + 1;
  470. }
  471. }
  472. // Alignment pattern ---------------------------------------------------
  473. // Positions of alignment patterns.
  474. // This array includes only the second and the third position of the
  475. // alignment patterns. Rest of them can be calculated from the distance
  476. // between them.
  477. // See Table 1 in Appendix E (pp.71) of JIS X0510:2004.
  478. public static $alignmentPattern = array(
  479. array( 0, 0),
  480. array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5
  481. array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10
  482. array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15
  483. array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20
  484. array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25
  485. array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), //26-30
  486. array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), //31-35
  487. array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58), //35-40
  488. );
  489. /** --------------------------------------------------------------------
  490. * Put an alignment marker.
  491. * @param frame
  492. * @param width
  493. * @param ox,oy center coordinate of the pattern
  494. */
  495. public static function putAlignmentMarker(array &$frame, $ox, $oy)
  496. {
  497. $finder = array(
  498. "\xa1\xa1\xa1\xa1\xa1",
  499. "\xa1\xa0\xa0\xa0\xa1",
  500. "\xa1\xa0\xa1\xa0\xa1",
  501. "\xa1\xa0\xa0\xa0\xa1",
  502. "\xa1\xa1\xa1\xa1\xa1"
  503. );
  504. $yStart = $oy-2;
  505. $xStart = $ox-2;
  506. for($y=0; $y<5; $y++) {
  507. QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]);
  508. }
  509. }
  510. //----------------------------------------------------------------------
  511. public static function putAlignmentPattern($version, &$frame, $width)
  512. {
  513. if($version < 2)
  514. return;
  515. $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0];
  516. if($d < 0) {
  517. $w = 2;
  518. } else {
  519. $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2);
  520. }
  521. if($w * $w - 3 == 1) {
  522. $x = self::$alignmentPattern[$version][0];
  523. $y = self::$alignmentPattern[$version][0];
  524. self::putAlignmentMarker($frame, $x, $y);
  525. return;
  526. }
  527. $cx = self::$alignmentPattern[$version][0];
  528. for($x=1; $x<$w - 1; $x++) {
  529. self::putAlignmentMarker($frame, 6, $cx);
  530. self::putAlignmentMarker($frame, $cx, 6);
  531. $cx += $d;
  532. }
  533. $cy = self::$alignmentPattern[$version][0];
  534. for($y=0; $y<$w-1; $y++) {
  535. $cx = self::$alignmentPattern[$version][0];
  536. for($x=0; $x<$w-1; $x++) {
  537. self::putAlignmentMarker($frame, $cx, $cy);
  538. $cx += $d;
  539. }
  540. $cy += $d;
  541. }
  542. }
  543. // Version information pattern -----------------------------------------
  544. // Version information pattern (BCH coded).
  545. // See Table 1 in Appendix D (pp.68) of JIS X0510:2004.
  546. // size: [QRSPEC_VERSION_MAX - 6]
  547. public static $versionPattern = array(
  548. 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d,
  549. 0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9,
  550. 0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75,
  551. 0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64,
  552. 0x27541, 0x28c69
  553. );
  554. //----------------------------------------------------------------------
  555. public static function getVersionPattern($version)
  556. {
  557. if($version < 7 || $version > QRSPEC_VERSION_MAX)
  558. return 0;
  559. return self::$versionPattern[$version -7];
  560. }
  561. // Format information --------------------------------------------------
  562. // See calcFormatInfo in tests/test_qrspec.c (orginal qrencode c lib)
  563. public static $formatInfo = array(
  564. array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976),
  565. array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0),
  566. array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed),
  567. array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b)
  568. );
  569. public static function getFormatInfo($mask, $level)
  570. {
  571. if($mask < 0 || $mask > 7)
  572. return 0;
  573. if($level < 0 || $level > 3)
  574. return 0;
  575. return self::$formatInfo[$level][$mask];
  576. }
  577. // Frame ---------------------------------------------------------------
  578. // Cache of initial frames.
  579. public static $frames = array();
  580. /** --------------------------------------------------------------------
  581. * Put a finder pattern.
  582. * @param frame
  583. * @param width
  584. * @param ox,oy upper-left coordinate of the pattern
  585. */
  586. public static function putFinderPattern(&$frame, $ox, $oy)
  587. {
  588. $finder = array(
  589. "\xc1\xc1\xc1\xc1\xc1\xc1\xc1",
  590. "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
  591. "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
  592. "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
  593. "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
  594. "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
  595. "\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
  596. );
  597. for($y=0; $y<7; $y++) {
  598. QRstr::set($frame, $ox, $oy+$y, $finder[$y]);
  599. }
  600. }
  601. //----------------------------------------------------------------------
  602. public static function createFrame($version)
  603. {
  604. $width = self::$capacity[$version][QRCAP_WIDTH];
  605. $frameLine = str_repeat ("\0", $width);
  606. $frame = array_fill(0, $width, $frameLine);
  607. // Finder pattern
  608. self::putFinderPattern($frame, 0, 0);
  609. self::putFinderPattern($frame, $width - 7, 0);
  610. self::putFinderPattern($frame, 0, $width - 7);
  611. // Separator
  612. $yOffset = $width - 7;
  613. for($y=0; $y<7; $y++) {
  614. $frame[$y][7] = "\xc0";
  615. $frame[$y][$width - 8] = "\xc0";
  616. $frame[$yOffset][7] = "\xc0";
  617. $yOffset++;
  618. }
  619. $setPattern = str_repeat("\xc0", 8);
  620. QRstr::set($frame, 0, 7, $setPattern);
  621. QRstr::set($frame, $width-8, 7, $setPattern);
  622. QRstr::set($frame, 0, $width - 8, $setPattern);
  623. // Format info
  624. $setPattern = str_repeat("\x84", 9);
  625. QRstr::set($frame, 0, 8, $setPattern);
  626. QRstr::set($frame, $width - 8, 8, $setPattern, 8);
  627. $yOffset = $width - 8;
  628. for($y=0; $y<8; $y++,$yOffset++) {
  629. $frame[$y][8] = "\x84";
  630. $frame[$yOffset][8] = "\x84";
  631. }
  632. // Timing pattern
  633. for($i=1; $i<$width-15; $i++) {
  634. $frame[6][7+$i] = chr(0x90 | ($i & 1));
  635. $frame[7+$i][6] = chr(0x90 | ($i & 1));
  636. }
  637. // Alignment pattern
  638. self::putAlignmentPattern($version, $frame, $width);
  639. // Version information
  640. if($version >= 7) {
  641. $vinf = self::getVersionPattern($version);
  642. $v = $vinf;
  643. for($x=0; $x<6; $x++) {
  644. for($y=0; $y<3; $y++) {
  645. $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
  646. $v = $v >> 1;
  647. }
  648. }
  649. $v = $vinf;
  650. for($y=0; $y<6; $y++) {
  651. for($x=0; $x<3; $x++) {
  652. $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));
  653. $v = $v >> 1;
  654. }
  655. }
  656. }
  657. // and a little bit...
  658. $frame[$width - 8][8] = "\x81";
  659. return $frame;
  660. }
  661. //----------------------------------------------------------------------
  662. public static function debug($frame, $binary_mode = false)
  663. {
  664. if ($binary_mode) {
  665. foreach ($frame as &$frameLine) {
  666. $frameLine = join('<span class="m">&nbsp;&nbsp;</span>', explode('0', $frameLine));
  667. $frameLine = join('&#9608;&#9608;', explode('1', $frameLine));
  668. }
  669. ?>
  670. <style>
  671. .m { background-color: white; }
  672. </style>
  673. <?php
  674. echo '<pre><tt><br/ ><br/ ><br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  675. echo join("<br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $frame);
  676. echo '</tt></pre><br/ ><br/ ><br/ ><br/ ><br/ ><br/ >';
  677. } else {
  678. foreach ($frame as &$frameLine) {
  679. $frameLine = join('<span class="m">&nbsp;</span>', explode("\xc0", $frameLine));
  680. $frameLine = join('<span class="m">&#9618;</span>', explode("\xc1", $frameLine));
  681. $frameLine = join('<span class="p">&nbsp;</span>', explode("\xa0", $frameLine));
  682. $frameLine = join('<span class="p">&#9618;</span>', explode("\xa1", $frameLine));
  683. $frameLine = join('<span class="s">&#9671;</span>', explode("\x84", $frameLine)); //format 0
  684. $frameLine = join('<span class="s">&#9670;</span>', explode("\x85", $frameLine)); //format 1
  685. $frameLine = join('<span class="x">&#9762;</span>', explode("\x81", $frameLine)); //special bit
  686. $frameLine = join('<span class="c">&nbsp;</span>', explode("\x90", $frameLine)); //clock 0
  687. $frameLine = join('<span class="c">&#9719;</span>', explode("\x91", $frameLine)); //clock 1
  688. $frameLine = join('<span class="f">&nbsp;</span>', explode("\x88", $frameLine)); //version
  689. $frameLine = join('<span class="f">&#9618;</span>', explode("\x89", $frameLine)); //version
  690. $frameLine = join('&#9830;', explode("\x01", $frameLine));
  691. $frameLine = join('&#8901;', explode("\0", $frameLine));
  692. }
  693. ?>
  694. <style>
  695. .p { background-color: yellow; }
  696. .m { background-color: #00FF00; }
  697. .s { background-color: #FF0000; }
  698. .c { background-color: aqua; }
  699. .x { background-color: pink; }
  700. .f { background-color: gold; }
  701. </style>
  702. <?php
  703. echo "<pre><tt>";
  704. echo join("<br/ >", $frame);
  705. echo "</tt></pre>";
  706. }
  707. }
  708. //----------------------------------------------------------------------
  709. public static function serial($frame)
  710. {
  711. return gzcompress(join("\n", $frame), 9);
  712. }
  713. //----------------------------------------------------------------------
  714. public static function unserial($code)
  715. {
  716. return explode("\n", gzuncompress($code));
  717. }
  718. //----------------------------------------------------------------------
  719. public static function newFrame($version)
  720. {
  721. if($version < 1 || $version > QRSPEC_VERSION_MAX)
  722. return null;
  723. if(!isset(self::$frames[$version])) {
  724. $fileName = QR_CACHE_DIR.'frame_'.$version.'.dat';
  725. if (QR_CACHEABLE) {
  726. if (file_exists($fileName)) {
  727. self::$frames[$version] = self::unserial(file_get_contents($fileName));
  728. } else {
  729. self::$frames[$version] = self::createFrame($version);
  730. file_put_contents($fileName, self::serial(self::$frames[$version]));
  731. }
  732. } else {
  733. self::$frames[$version] = self::createFrame($version);
  734. }
  735. }
  736. if(is_null(self::$frames[$version]))
  737. return null;
  738. return self::$frames[$version];
  739. }
  740. //----------------------------------------------------------------------
  741. public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; }
  742. public static function rsBlockNum1($spec) { return $spec[0]; }
  743. public static function rsDataCodes1($spec) { return $spec[1]; }
  744. public static function rsEccCodes1($spec) { return $spec[2]; }
  745. public static function rsBlockNum2($spec) { return $spec[3]; }
  746. public static function rsDataCodes2($spec) { return $spec[4]; }
  747. public static function rsEccCodes2($spec) { return $spec[2]; }
  748. public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); }
  749. public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; }
  750. }
  751. //---- qrimage.php -----------------------------
  752. /*
  753. * PHP QR Code encoder
  754. *
  755. * Image output of code using GD2
  756. *
  757. * PHP QR Code is distributed under LGPL 3
  758. * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
  759. *
  760. * This library is free software; you can redistribute it and/or
  761. * modify it under the terms of the GNU Lesser General Public
  762. * License as published by the Free Software Foundation; either
  763. * version 3 of the License, or any later version.
  764. *
  765. * This library is distributed in the hope that it will be useful,
  766. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  767. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  768. * Lesser General Public License for more details.
  769. *
  770. * You should have received a copy of the GNU Lesser General Public
  771. * License along with this library; if not, write to the Free Software
  772. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  773. */
  774. define('QR_IMAGE', true);
  775. class QRimage {
  776. //----------------------------------------------------------------------
  777. public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color, $fore_color)
  778. {
  779. $image = self::image($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color);
  780. if ($filename === false) {
  781. Header("Content-type: image/png");
  782. ImagePng($image);
  783. } else {
  784. if($saveandprint===TRUE){
  785. ImagePng($image, $filename);
  786. header("Content-type: image/png");
  787. ImagePng($image);
  788. }else{
  789. ImagePng($image, $filename);
  790. }
  791. }
  792. ImageDestroy($image);
  793. }
  794. //----------------------------------------------------------------------
  795. public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85)
  796. {
  797. $image = self::image($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color);
  798. if ($filename === false) {
  799. Header("Content-type: image/jpeg");
  800. ImageJpeg($image, null, $q);
  801. } else {
  802. ImageJpeg($image, $filename, $q);
  803. }
  804. ImageDestroy($image);
  805. }
  806. //----------------------------------------------------------------------
  807. private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $back_color = 0xFFFFFF, $fore_color = 0x000000)
  808. {
  809. $h = count($frame);
  810. $w = strlen($frame[0]);
  811. $imgW = $w + 2*$outerFrame;
  812. $imgH = $h + 2*$outerFrame;
  813. $base_image =ImageCreate($imgW, $imgH);
  814. // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
  815. $r1 = round((($fore_color & 0xFF0000) >> 16), 5);
  816. $b1 = round((($fore_color & 0x00FF00) >> 8), 5);
  817. $g1 = round(($fore_color & 0x0000FF), 5);
  818. // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
  819. $r2 = round((($back_color & 0xFF0000) >> 16), 5);
  820. $b2 = round((($back_color & 0x00FF00) >> 8), 5);
  821. $g2 = round(($back_color & 0x0000FF), 5);
  822. $col[0] = ImageColorAllocate($base_image,$r2,$b2,$g2);
  823. $col[1] = ImageColorAllocate($base_image,$r1,$b1,$g1);
  824. imagefill($base_image, 0, 0, $col[0]);
  825. for($y=0; $y<$h; $y++) {
  826. for($x=0; $x<$w; $x++) {
  827. if ($frame[$y][$x] == '1') {
  828. ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]);
  829. }
  830. }
  831. }
  832. $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
  833. ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
  834. ImageDestroy($base_image);
  835. return $target_image;
  836. }
  837. }
  838. //---- qrinput.php -----------------------------
  839. /*
  840. * PHP QR Code encoder
  841. *
  842. * Input encoding class
  843. *
  844. * Based on libqrencode C library distributed under LGPL 2.1
  845. * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
  846. *
  847. * PHP QR Code is distributed under LGPL 3
  848. * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
  849. *
  850. * This library is free software; you can redistribute it and/or
  851. * modify it under the terms of the GNU Lesser General Public
  852. * License as published by the Free Software Foundation; either
  853. * version 3 of the License, or any later version.
  854. *
  855. * This library is distributed in the hope that it will be useful,
  856. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  857. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  858. * Lesser General Public License for more details.
  859. *
  860. * You should have received a copy of the GNU Lesser General Public
  861. * License along with this library; if not, write to the Free Software
  862. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  863. */
  864. define('STRUCTURE_HEADER_BITS', 20);
  865. define('MAX_STRUCTURED_SYMBOLS', 16);
  866. class QRinputItem {
  867. public $mode;
  868. public $size;
  869. public $data;
  870. public $bstream;
  871. public function __construct($mode, $size, $data, $bstream = null)
  872. {
  873. $setData = array_slice($data, 0, $size);
  874. if (count($setData) < $size) {
  875. $setData = array_merge($setData, array_fill(0,$size-count($setData),0));
  876. }
  877. if(!QRinput::check($mode, $size, $setData)) {
  878. throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData));
  879. return null;
  880. }
  881. $this->mode = $mode;
  882. $this->size = $size;
  883. $this->data = $setData;
  884. $this->bstream = $bstream;
  885. }
  886. //----------------------------------------------------------------------
  887. public function encodeModeNum($version)
  888. {
  889. try {
  890. $words = (int)($this->size / 3);
  891. $bs = new QRbitstream();
  892. $val = 0x1;
  893. $bs->appendNum(4, $val);
  894. $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size);
  895. for($i=0; $i<$words; $i++) {
  896. $val = (ord($this->data[$i*3 ]) - ord('0')) * 100;
  897. $val += (ord($this->data[$i*3+1]) - ord('0')) * 10;
  898. $val += (ord($this->data[$i*3+2]) - ord('0'));
  899. $bs->appendNum(10, $val);
  900. }
  901. if($this->size - $words * 3 == 1) {
  902. $val = ord($this->data[$words*3]) - ord('0');
  903. $bs->appendNum(4, $val);
  904. } else if($this->size - $words * 3 == 2) {
  905. $val = (ord($this->data[$words*3 ]) - ord('0')) * 10;
  906. $val += (ord($this->data[$words*3+1]) - ord('0'));
  907. $bs->appendNum(7, $val);
  908. }
  909. $this->bstream = $bs;
  910. return 0;
  911. } catch (Exception $e) {
  912. return -1;
  913. }
  914. }
  915. //----------------------------------------------------------------------
  916. public function encodeModeAn($version)
  917. {
  918. try {
  919. $words = (int)($this->size / 2);
  920. $bs = new QRbitstream();
  921. $bs->appendNum(4, 0x02);
  922. $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size);
  923. for($i=0; $i<$words; $i++) {
  924. $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45;
  925. $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1]));
  926. $bs->appendNum(11, $val);
  927. }
  928. if($this->size & 1) {
  929. $val = QRinput::lookAnTable(ord($this->data[$words * 2]));
  930. $bs->appendNum(6, $val);
  931. }
  932. $this->bstream = $bs;
  933. return 0;
  934. } catch (Exception $e) {
  935. return -1;
  936. }
  937. }
  938. //----------------------------------------------------------------------
  939. public function encodeMode8($version)
  940. {
  941. try {
  942. $bs = new QRbitstream();
  943. $bs->appendNum(4, 0x4);
  944. $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size);
  945. for($i=0; $i<$this->size; $i++) {
  946. $bs->appendNum(8, ord($this->data[$i]));
  947. }
  948. $this->bstream = $bs;
  949. return 0;
  950. } catch (Exception $e) {
  951. return -1;
  952. }
  953. }
  954. //----------------------------------------------------------------------
  955. public function encodeModeKanji($version)
  956. {
  957. try {
  958. $bs = new QRbitrtream();
  959. $bs->appendNum(4, 0x8);
  960. $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2));
  961. for($i=0; $i<$this->size; $i+=2) {
  962. $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]);
  963. if($val <= 0x9ffc) {
  964. $val -= 0x8140;
  965. } else {
  966. $val -= 0xc140;
  967. }
  968. $h = ($val >> 8) * 0xc0;
  969. $val = ($val & 0xff) + $h;
  970. $bs->appendNum(13, $val);
  971. }
  972. $this->bstream = $bs;
  973. return 0;
  974. } catch (Exception $e) {
  975. return -1;
  976. }
  977. }
  978. //----------------------------------------------------------------------
  979. public function encodeModeStructure()
  980. {
  981. try {
  982. $bs = new QRbitstream();
  983. $bs->appendNum(4, 0x03);
  984. $bs->appendNum(4, ord($this->data[1]) - 1);
  985. $bs->appendNum(4, ord($this->data[0]) - 1);
  986. $bs->appendNum(8, ord($this->data[2]));
  987. $this->bstream = $bs;
  988. return 0;
  989. } catch (Exception $e) {
  990. return -1;
  991. }
  992. }
  993. //----------------------------------------------------------------------
  994. public function estimateBitStreamSizeOfEntry($version)
  995. {
  996. $bits = 0;
  997. if($version == 0)
  998. $version = 1;
  999. switch($this->mode) {
  1000. case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break;
  1001. case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break;
  1002. case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break;
  1003. case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break;
  1004. case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS;
  1005. default:
  1006. return 0;
  1007. }
  1008. $l = QRspec::lengthIndicator($this->mode, $version);
  1009. $m = 1 << $l;
  1010. $num = (int)(($this->size + $m - 1) / $m);
  1011. $bits += $num * (4 + $l);
  1012. return $bits;
  1013. }
  1014. //----------------------------------------------------------------------
  1015. public function encodeBitStream($version)
  1016. {
  1017. try {
  1018. unset($this->bstream);
  1019. $words = QRspec::maximumWords($this->mode, $version);
  1020. if($this->size > $words) {
  1021. $st1 = new QRinputItem($this->mode, $words, $this->data);
  1022. $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words));
  1023. $st1->encodeBitStream($version);
  1024. $st2->encodeBitStream($version);
  1025. $this->bstream = new QRbitstream();
  1026. $this->

Large files files are truncated, but you can click here to view the full file