]>
Raphaël G. Git Repositories - cdn/blob - vendor/phpqrcode/qrtools.php
5 * Toolset, handy and debug utilites.
7 * PHP QR Code is distributed under LGPL 3
8 * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 3 of the License, or any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 //----------------------------------------------------------------------
28 public static function binarize($frame)
31 foreach ($frame as &$frameLine) {
33 for($i=0; $i<$len; $i++
) {
34 $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
41 //----------------------------------------------------------------------
42 public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037')
44 $barcode_array = array();
47 $mode = explode(',', $mode);
51 if (count($mode) > 1) {
55 $qrTab = QRcode
::text($code, false, $eccLevel);
56 $size = count($qrTab);
58 $barcode_array['num_rows'] = $size;
59 $barcode_array['num_cols'] = $size;
60 $barcode_array['bcode'] = array();
62 foreach ($qrTab as $line) {
64 foreach(str_split($line) as $char)
65 $arrAdd[] = ($char=='1')?1:0;
66 $barcode_array['bcode'][] = $arrAdd;
69 return $barcode_array;
72 //----------------------------------------------------------------------
73 public static function clearCache()
75 self
::$frames = array();
78 //----------------------------------------------------------------------
79 public static function buildCache()
81 QRtools
::markTime('before_build_cache');
84 for ($a=1; $a <= QRSPEC_VERSION_MAX
; $a++
) {
85 $frame = QRspec
::newFrame($a);
87 $fileName = QR_CACHE_DIR
.'frame_'.$a.'.png';
88 QRimage
::png(self
::binarize($frame), $fileName, 1, 0);
91 $width = count($frame);
92 $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
93 for ($maskNo=0; $maskNo<8; $maskNo++
)
94 $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
97 QRtools
::markTime('after_build_cache');
100 //----------------------------------------------------------------------
101 public static function log($outfile, $err)
103 if (QR_LOG_DIR
!== false) {
105 if ($outfile !== false) {
106 file_put_contents(QR_LOG_DIR
.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND
);
108 file_put_contents(QR_LOG_DIR
.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND
);
114 //----------------------------------------------------------------------
115 public static function dumpMask($frame)
117 $width = count($frame);
118 for($y=0;$y<$width;$y++
) {
119 for($x=0;$x<$width;$x++
) {
120 echo ord($frame[$y][$x]).',';
125 //----------------------------------------------------------------------
126 public static function markTime($markerId)
128 list($usec, $sec) = explode(" ", microtime());
129 $time = ((float)$usec +
(float)$sec);
131 if (!isset($GLOBALS['qr_time_bench']))
132 $GLOBALS['qr_time_bench'] = array();
134 $GLOBALS['qr_time_bench'][$markerId] = $time;
137 //----------------------------------------------------------------------
138 public static function timeBenchmark()
140 self
::markTime('finish');
146 echo '<table cellpadding="3" cellspacing="1">
147 <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead>
150 foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
152 echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>';
154 $startTime = $thisTime;
158 $lastTime = $thisTime;
161 echo '</tbody><tfoot>
162 <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr>
167 public static function save($content, $filename_path)
170 $handle = fopen($filename_path, "w");
171 fwrite($handle, $content);
174 } catch (Exception
$e) {
175 echo 'Exception reçue : ', $e->getMessage(), "\n";
182 //##########################################################################
184 QRtools
::markTime('start');