Upload files to "qrcode"
Signed-off-by: kevinowino869 <kevinowino869@www.codelab.nestict.africa>
This commit is contained in:
parent
012bf85d6b
commit
2c743cb0f3
45
qrcode/README
Normal file
45
qrcode/README
Normal file
@ -0,0 +1,45 @@
|
||||
This is PHP implementation of QR Code 2-D barcode generator. It is pure-php
|
||||
LGPL-licensed implementation based on C libqrencode by Kentaro Fukuchi.
|
||||
|
||||
== LICENSING ==
|
||||
|
||||
Copyright (C) 2010 by Dominik Dzienia
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. See the GNU Lesser General Public License (LICENSE file)
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this library; if not, write to the Free Software Foundation, Inc., 51
|
||||
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
== INSTALATION AND USAGE ==
|
||||
|
||||
* INSTALL file
|
||||
* http://sourceforge.net/apps/mediawiki/phpqrcode/index.php?title=Main_Page
|
||||
|
||||
== CONTACT ==
|
||||
|
||||
Fell free to contact me via e-mail (deltalab at poczta dot fm) or using
|
||||
folowing project pages:
|
||||
|
||||
* http://sourceforge.net/projects/phpqrcode/
|
||||
* http://phpqrcode.sourceforge.net/
|
||||
|
||||
== ACKNOWLEDGMENTS ==
|
||||
|
||||
Based on C libqrencode library (ver. 3.1.1)
|
||||
Copyright (C) 2006-2010 by Kentaro Fukuchi
|
||||
http://megaui.net/fukuchi/works/qrencode/index.en.html
|
||||
|
||||
QR Code is registered trademarks of DENSO WAVE INCORPORATED in JAPAN and other
|
||||
countries.
|
||||
|
||||
Reed-Solomon code encoder is written by Phil Karn, KA9Q.
|
||||
Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q
|
||||
|
2
qrcode/VERSION
Normal file
2
qrcode/VERSION
Normal file
@ -0,0 +1,2 @@
|
||||
1.1.4
|
||||
2010100721
|
311
qrcode/qrsplit.php
Normal file
311
qrcode/qrsplit.php
Normal file
@ -0,0 +1,311 @@
|
||||
<?php
|
||||
/*
|
||||
* PHP QR Code encoder
|
||||
*
|
||||
* Input splitting classes
|
||||
*
|
||||
* Based on libqrencode C library distributed under LGPL 2.1
|
||||
* Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
|
||||
*
|
||||
* PHP QR Code is distributed under LGPL 3
|
||||
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
||||
*
|
||||
* The following data / specifications are taken from
|
||||
* "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004)
|
||||
* or
|
||||
* "Automatic identification and data capture techniques --
|
||||
* QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006)
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
class QRsplit {
|
||||
|
||||
public $dataStr = '';
|
||||
public $input;
|
||||
public $modeHint;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public function __construct($dataStr, $input, $modeHint)
|
||||
{
|
||||
$this->dataStr = $dataStr;
|
||||
$this->input = $input;
|
||||
$this->modeHint = $modeHint;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public static function isdigitat($str, $pos)
|
||||
{
|
||||
if ($pos >= strlen($str))
|
||||
return false;
|
||||
|
||||
return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public static function isalnumat($str, $pos)
|
||||
{
|
||||
if ($pos >= strlen($str))
|
||||
return false;
|
||||
|
||||
return (QRinput::lookAnTable(ord($str[$pos])) >= 0);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public function identifyMode($pos)
|
||||
{
|
||||
if ($pos >= strlen($this->dataStr))
|
||||
return QR_MODE_NUL;
|
||||
|
||||
$c = $this->dataStr[$pos];
|
||||
|
||||
if(self::isdigitat($this->dataStr, $pos)) {
|
||||
return QR_MODE_NUM;
|
||||
} else if(self::isalnumat($this->dataStr, $pos)) {
|
||||
return QR_MODE_AN;
|
||||
} else if($this->modeHint == QR_MODE_KANJI) {
|
||||
|
||||
if ($pos+1 < strlen($this->dataStr))
|
||||
{
|
||||
$d = $this->dataStr[$pos+1];
|
||||
$word = (ord($c) << 8) | ord($d);
|
||||
if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) {
|
||||
return QR_MODE_KANJI;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QR_MODE_8;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public function eatNum()
|
||||
{
|
||||
$ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
|
||||
|
||||
$p = 0;
|
||||
while(self::isdigitat($this->dataStr, $p)) {
|
||||
$p++;
|
||||
}
|
||||
|
||||
$run = $p;
|
||||
$mode = $this->identifyMode($p);
|
||||
|
||||
if($mode == QR_MODE_8) {
|
||||
$dif = QRinput::estimateBitsModeNum($run) + 4 + $ln
|
||||
+ QRinput::estimateBitsMode8(1) // + 4 + l8
|
||||
- QRinput::estimateBitsMode8($run + 1); // - 4 - l8
|
||||
if($dif > 0) {
|
||||
return $this->eat8();
|
||||
}
|
||||
}
|
||||
if($mode == QR_MODE_AN) {
|
||||
$dif = QRinput::estimateBitsModeNum($run) + 4 + $ln
|
||||
+ QRinput::estimateBitsModeAn(1) // + 4 + la
|
||||
- QRinput::estimateBitsModeAn($run + 1);// - 4 - la
|
||||
if($dif > 0) {
|
||||
return $this->eatAn();
|
||||
}
|
||||
}
|
||||
|
||||
$ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr));
|
||||
if($ret < 0)
|
||||
return -1;
|
||||
|
||||
return $run;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public function eatAn()
|
||||
{
|
||||
$la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion());
|
||||
$ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
|
||||
|
||||
$p = 0;
|
||||
|
||||
while(self::isalnumat($this->dataStr, $p)) {
|
||||
if(self::isdigitat($this->dataStr, $p)) {
|
||||
$q = $p;
|
||||
while(self::isdigitat($this->dataStr, $q)) {
|
||||
$q++;
|
||||
}
|
||||
|
||||
$dif = QRinput::estimateBitsModeAn($p) // + 4 + la
|
||||
+ QRinput::estimateBitsModeNum($q - $p) + 4 + $ln
|
||||
- QRinput::estimateBitsModeAn($q); // - 4 - la
|
||||
|
||||
if($dif < 0) {
|
||||
break;
|
||||
} else {
|
||||
$p = $q;
|
||||
}
|
||||
} else {
|
||||
$p++;
|
||||
}
|
||||
}
|
||||
|
||||
$run = $p;
|
||||
|
||||
if(!self::isalnumat($this->dataStr, $p)) {
|
||||
$dif = QRinput::estimateBitsModeAn($run) + 4 + $la
|
||||
+ QRinput::estimateBitsMode8(1) // + 4 + l8
|
||||
- QRinput::estimateBitsMode8($run + 1); // - 4 - l8
|
||||
if($dif > 0) {
|
||||
return $this->eat8();
|
||||
}
|
||||
}
|
||||
|
||||
$ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr));
|
||||
if($ret < 0)
|
||||
return -1;
|
||||
|
||||
return $run;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public function eatKanji()
|
||||
{
|
||||
$p = 0;
|
||||
|
||||
while($this->identifyMode($p) == QR_MODE_KANJI) {
|
||||
$p += 2;
|
||||
}
|
||||
|
||||
$ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr));
|
||||
if($ret < 0)
|
||||
return -1;
|
||||
|
||||
return $run;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public function eat8()
|
||||
{
|
||||
$la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion());
|
||||
$ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
|
||||
|
||||
$p = 1;
|
||||
$dataStrLen = strlen($this->dataStr);
|
||||
|
||||
while($p < $dataStrLen) {
|
||||
|
||||
$mode = $this->identifyMode($p);
|
||||
if($mode == QR_MODE_KANJI) {
|
||||
break;
|
||||
}
|
||||
if($mode == QR_MODE_NUM) {
|
||||
$q = $p;
|
||||
while(self::isdigitat($this->dataStr, $q)) {
|
||||
$q++;
|
||||
}
|
||||
$dif = QRinput::estimateBitsMode8($p) // + 4 + l8
|
||||
+ QRinput::estimateBitsModeNum($q - $p) + 4 + $ln
|
||||
- QRinput::estimateBitsMode8($q); // - 4 - l8
|
||||
if($dif < 0) {
|
||||
break;
|
||||
} else {
|
||||
$p = $q;
|
||||
}
|
||||
} else if($mode == QR_MODE_AN) {
|
||||
$q = $p;
|
||||
while(self::isalnumat($this->dataStr, $q)) {
|
||||
$q++;
|
||||
}
|
||||
$dif = QRinput::estimateBitsMode8($p) // + 4 + l8
|
||||
+ QRinput::estimateBitsModeAn($q - $p) + 4 + $la
|
||||
- QRinput::estimateBitsMode8($q); // - 4 - l8
|
||||
if($dif < 0) {
|
||||
break;
|
||||
} else {
|
||||
$p = $q;
|
||||
}
|
||||
} else {
|
||||
$p++;
|
||||
}
|
||||
}
|
||||
|
||||
$run = $p;
|
||||
$ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr));
|
||||
|
||||
if($ret < 0)
|
||||
return -1;
|
||||
|
||||
return $run;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public function splitString()
|
||||
{
|
||||
while (strlen($this->dataStr) > 0)
|
||||
{
|
||||
if($this->dataStr == '')
|
||||
return 0;
|
||||
|
||||
$mode = $this->identifyMode(0);
|
||||
|
||||
switch ($mode) {
|
||||
case QR_MODE_NUM: $length = $this->eatNum(); break;
|
||||
case QR_MODE_AN: $length = $this->eatAn(); break;
|
||||
case QR_MODE_KANJI:
|
||||
if ($hint == QR_MODE_KANJI)
|
||||
$length = $this->eatKanji();
|
||||
else $length = $this->eat8();
|
||||
break;
|
||||
default: $length = $this->eat8(); break;
|
||||
|
||||
}
|
||||
|
||||
if($length == 0) return 0;
|
||||
if($length < 0) return -1;
|
||||
|
||||
$this->dataStr = substr($this->dataStr, $length);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public function toUpper()
|
||||
{
|
||||
$stringLen = strlen($this->dataStr);
|
||||
$p = 0;
|
||||
|
||||
while ($p<$stringLen) {
|
||||
$mode = self::identifyMode(substr($this->dataStr, $p), $this->modeHint);
|
||||
if($mode == QR_MODE_KANJI) {
|
||||
$p += 2;
|
||||
} else {
|
||||
if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) {
|
||||
$this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32);
|
||||
}
|
||||
$p++;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->dataStr;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true)
|
||||
{
|
||||
if(is_null($string) || $string == '\0' || $string == '') {
|
||||
throw new Exception('empty string!!!');
|
||||
}
|
||||
|
||||
$split = new QRsplit($string, $input, $modeHint);
|
||||
|
||||
if(!$casesensitive)
|
||||
$split->toUpper();
|
||||
|
||||
return $split->splitString();
|
||||
}
|
||||
}
|
172
qrcode/qrtools.php
Normal file
172
qrcode/qrtools.php
Normal file
@ -0,0 +1,172 @@
|
||||
<?php
|
||||
/*
|
||||
* PHP QR Code encoder
|
||||
*
|
||||
* Toolset, handy and debug utilites.
|
||||
*
|
||||
* PHP QR Code is distributed under LGPL 3
|
||||
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
class QRtools {
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public static function binarize($frame)
|
||||
{
|
||||
$len = count($frame);
|
||||
foreach ($frame as &$frameLine) {
|
||||
|
||||
for($i=0; $i<$len; $i++) {
|
||||
$frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
|
||||
}
|
||||
}
|
||||
|
||||
return $frame;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037')
|
||||
{
|
||||
$barcode_array = array();
|
||||
|
||||
if (!is_array($mode))
|
||||
$mode = explode(',', $mode);
|
||||
|
||||
$eccLevel = 'L';
|
||||
|
||||
if (count($mode) > 1) {
|
||||
$eccLevel = $mode[1];
|
||||
}
|
||||
|
||||
$qrTab = QRcode::text($code, false, $eccLevel);
|
||||
$size = count($qrTab);
|
||||
|
||||
$barcode_array['num_rows'] = $size;
|
||||
$barcode_array['num_cols'] = $size;
|
||||
$barcode_array['bcode'] = array();
|
||||
|
||||
foreach ($qrTab as $line) {
|
||||
$arrAdd = array();
|
||||
foreach(str_split($line) as $char)
|
||||
$arrAdd[] = ($char=='1')?1:0;
|
||||
$barcode_array['bcode'][] = $arrAdd;
|
||||
}
|
||||
|
||||
return $barcode_array;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public static function clearCache()
|
||||
{
|
||||
self::$frames = array();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public static function buildCache()
|
||||
{
|
||||
QRtools::markTime('before_build_cache');
|
||||
|
||||
$mask = new QRmask();
|
||||
for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
|
||||
$frame = QRspec::newFrame($a);
|
||||
if (QR_IMAGE) {
|
||||
$fileName = QR_CACHE_DIR.'frame_'.$a.'.png';
|
||||
QRimage::png(self::binarize($frame), $fileName, 1, 0);
|
||||
}
|
||||
|
||||
$width = count($frame);
|
||||
$bitMask = array_fill(0, $width, array_fill(0, $width, 0));
|
||||
for ($maskNo=0; $maskNo<8; $maskNo++)
|
||||
$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
|
||||
}
|
||||
|
||||
QRtools::markTime('after_build_cache');
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public static function log($outfile, $err)
|
||||
{
|
||||
if (QR_LOG_DIR !== false) {
|
||||
if ($err != '') {
|
||||
if ($outfile !== false) {
|
||||
file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
|
||||
} else {
|
||||
file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public static function dumpMask($frame)
|
||||
{
|
||||
$width = count($frame);
|
||||
for($y=0;$y<$width;$y++) {
|
||||
for($x=0;$x<$width;$x++) {
|
||||
echo ord($frame[$y][$x]).',';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public static function markTime($markerId)
|
||||
{
|
||||
list($usec, $sec) = explode(" ", microtime());
|
||||
$time = ((float)$usec + (float)$sec);
|
||||
|
||||
if (!isset($GLOBALS['qr_time_bench']))
|
||||
$GLOBALS['qr_time_bench'] = array();
|
||||
|
||||
$GLOBALS['qr_time_bench'][$markerId] = $time;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public static function timeBenchmark()
|
||||
{
|
||||
self::markTime('finish');
|
||||
|
||||
$lastTime = 0;
|
||||
$startTime = 0;
|
||||
$p = 0;
|
||||
|
||||
echo '<table cellpadding="3" cellspacing="1">
|
||||
<thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead>
|
||||
<tbody>';
|
||||
|
||||
foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
|
||||
if ($p > 0) {
|
||||
echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>';
|
||||
} else {
|
||||
$startTime = $thisTime;
|
||||
}
|
||||
|
||||
$p++;
|
||||
$lastTime = $thisTime;
|
||||
}
|
||||
|
||||
echo '</tbody><tfoot>
|
||||
<tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr>
|
||||
</tfoot>
|
||||
</table>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//##########################################################################
|
||||
|
||||
QRtools::markTime('start');
|
||||
|
Loading…
x
Reference in New Issue
Block a user