QRtools

PHP QR Code encoder.

Defined (1)

The class is defined in the following location(s).

/includes/phpqrcode/phpqrcode.php  
  1. class QRtools { 
  2.  
  3. //---------------------------------------------------------------------- 
  4. public static function binarize($frame) 
  5. $len = count($frame); 
  6. foreach ($frame as &$frameLine) { 
  7.  
  8. for($i=0; $i<$len; $i++) { 
  9. $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; 
  10.  
  11. return $frame; 
  12.  
  13. //---------------------------------------------------------------------- 
  14. public static function tcpdfBarcodeArray($code, $mode = 'QR, L', $tcPdfVersion = '4.5.037') 
  15. $barcode_array = array(); 
  16.  
  17. if (!is_array($mode)) 
  18. $mode = explode(', ', $mode); 
  19.  
  20. $eccLevel = 'L'; 
  21.  
  22. if (count($mode) > 1) { 
  23. $eccLevel = $mode[1]; 
  24.  
  25. $qrTab = QRcode::text($code, false, $eccLevel); 
  26. $size = count($qrTab); 
  27.  
  28. $barcode_array['num_rows'] = $size; 
  29. $barcode_array['num_cols'] = $size; 
  30. $barcode_array['bcode'] = array(); 
  31.  
  32. foreach ($qrTab as $line) { 
  33. $arrAdd = array(); 
  34. foreach(str_split($line) as $char) 
  35. $arrAdd[] = ($char=='1')?1:0; 
  36. $barcode_array['bcode'][] = $arrAdd; 
  37.  
  38. return $barcode_array; 
  39.  
  40. //---------------------------------------------------------------------- 
  41. public static function clearCache() 
  42. self::$frames = array(); 
  43.  
  44. //---------------------------------------------------------------------- 
  45. public static function buildCache() 
  46. QRtools::markTime('before_build_cache'); 
  47.  
  48. $mask = new QRmask(); 
  49. for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) { 
  50. $frame = QRspec::newFrame($a); 
  51. if (QR_IMAGE) { 
  52. $fileName = QR_CACHE_DIR.'frame_'.$a.'.png'; 
  53. QRimage::png(self::binarize($frame), $fileName, 1, 0); 
  54.  
  55. $width = count($frame); 
  56. $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); 
  57. for ($maskNo=0; $maskNo<8; $maskNo++) 
  58. $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); 
  59.  
  60. QRtools::markTime('after_build_cache'); 
  61.  
  62. //---------------------------------------------------------------------- 
  63. public static function log($outfile, $err) 
  64. if (QR_LOG_DIR !== false) { 
  65. if ($err != '') { 
  66. if ($outfile !== false) { 
  67. file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); 
  68. } else { 
  69. file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); 
  70.  
  71. //---------------------------------------------------------------------- 
  72. public static function dumpMask($frame) 
  73. $width = count($frame); 
  74. for($y=0;$y<$width;$y++) { 
  75. for($x=0;$x<$width;$x++) { 
  76. echo ord($frame[$y][$x]).', '; 
  77.  
  78. //---------------------------------------------------------------------- 
  79. public static function markTime($markerId) 
  80. list($usec, $sec) = explode(" ", microtime()); 
  81. $time = ((float)$usec + (float)$sec); 
  82.  
  83. if (!isset($GLOBALS['qr_time_bench'])) 
  84. $GLOBALS['qr_time_bench'] = array(); 
  85.  
  86. $GLOBALS['qr_time_bench'][$markerId] = $time; 
  87.  
  88. //---------------------------------------------------------------------- 
  89. public static function timeBenchmark() 
  90. self::markTime('finish'); 
  91.  
  92. $lastTime = 0; 
  93. $startTime = 0; 
  94. $p = 0; 
  95.  
  96. echo '<table cellpadding="3" cellspacing="1"> 
  97. <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead> 
  98. <tbody>'; 
  99.  
  100. foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { 
  101. if ($p > 0) { 
  102. echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>'; 
  103. } else { 
  104. $startTime = $thisTime; 
  105.  
  106. $p++; 
  107. $lastTime = $thisTime; 
  108.  
  109. echo '</tbody><tfoot> 
  110. <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr> 
  111. </tfoot> 
  112. </table>'; 
  113.