PageRenderTime 58ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/gravityforms/includes/phpqrcode/phpqrcode.php

https://bitbucket.org/theshipswakecreative/psw
PHP | 3316 lines | 2163 code | 658 blank | 495 comment | 418 complexity | 11051877a544e8cddebd8a3ca55bba10 MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0

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

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

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