diff --git a/phpqrcode.php b/phpqrcode.php
index c2c92f0..035ff25 100755
--- a/phpqrcode.php
+++ b/phpqrcode.php
@@ -33,8 +33,8 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
-
+
+
/*
* Version: 1.1.4
@@ -74,9 +74,9 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
+
// Encoding modes
-
+
define('QR_MODE_NUL', -1);
define('QR_MODE_NUM', 0);
define('QR_MODE_AN', 1);
@@ -90,17 +90,17 @@
define('QR_ECLEVEL_M', 1);
define('QR_ECLEVEL_Q', 2);
define('QR_ECLEVEL_H', 3);
-
+
// Supported output formats
-
+
define('QR_FORMAT_TEXT', 0);
define('QR_FORMAT_PNG', 1);
-
+
class qrstr {
public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
$srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl));
}
- }
+ }
@@ -114,17 +114,17 @@
*
* Config file, tuned-up for merged verion
*/
-
+
define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there
define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true
- define('QR_LOG_DIR', false); // default error logs dir
-
+ define('QR_LOG_DIR', false); // default error logs dir
+
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
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
define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
-
+
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
-
+
@@ -157,63 +157,63 @@
*/
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);
@@ -221,13 +221,13 @@
$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');
}
@@ -241,12 +241,12 @@
} else {
file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
}
- }
+ }
}
}
-
+
//----------------------------------------------------------------------
- public static function dumpMask($frame)
+ public static function dumpMask($frame)
{
$width = count($frame);
for($y=0;$y<$width;$y++) {
@@ -255,24 +255,24 @@
}
}
}
-
+
//----------------------------------------------------------------------
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;
@@ -287,19 +287,19 @@
} else {
$startTime = $thisTime;
}
-
+
$p++;
$lastTime = $thisTime;
}
-
+
echo '
TOTAL: | '.number_format($lastTime-$startTime, 6).'s |
';
}
-
+
public static function save($content, $filename_path)
- {
+ {
try {
$handle = fopen($filename_path, "w");
fwrite($handle, $content);
@@ -307,16 +307,16 @@
return true;
} catch (Exception $e) {
echo 'Exception reçue : ', $e->getMessage(), "\n";
- }
-
+ }
+
}
-
+
}
-
+
//##########################################################################
-
+
QRtools::markTime('start');
-
+
@@ -339,7 +339,7 @@
* The following data / specifications are taken from
* "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004)
* or
- * "Automatic identification and data capture techniques --
+ * "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
@@ -356,7 +356,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
+
define('QRSPEC_VERSION_MAX', 40);
define('QRSPEC_WIDTH_MAX', 177);
@@ -366,7 +366,7 @@
define('QRCAP_EC', 3);
class QRspec {
-
+
public static $capacity = array(
array( 0, 0, 0, array( 0, 0, 0, 0)),
array( 21, 26, 0, array( 7, 10, 13, 17)), // 1
@@ -410,59 +410,59 @@
array(173, 3532, 0, array( 720, 1316, 1950, 2310)),
array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40
);
-
+
//----------------------------------------------------------------------
public static function getDataLength($version, $level)
{
return self::$capacity[$version][QRCAP_WORDS] - self::$capacity[$version][QRCAP_EC][$level];
}
-
+
//----------------------------------------------------------------------
public static function getECCLength($version, $level)
{
return self::$capacity[$version][QRCAP_EC][$level];
}
-
+
//----------------------------------------------------------------------
public static function getWidth($version)
{
return self::$capacity[$version][QRCAP_WIDTH];
}
-
+
//----------------------------------------------------------------------
public static function getRemainder($version)
{
return self::$capacity[$version][QRCAP_REMINDER];
}
-
+
//----------------------------------------------------------------------
public static function getMinimumVersion($size, $level)
{
for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
$words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level];
- if($words >= $size)
+ if($words >= $size)
return $i;
}
return -1;
}
-
+
//######################################################################
-
+
public static $lengthTableBits = array(
array(10, 12, 14),
array( 9, 11, 13),
array( 8, 16, 16),
array( 8, 10, 12)
);
-
+
//----------------------------------------------------------------------
public static function lengthIndicator($mode, $version)
{
if ($mode == QR_MODE_STRUCTURE)
return 0;
-
+
if ($version <= 9) {
$l = 0;
} else if ($version <= 26) {
@@ -473,13 +473,13 @@
return self::$lengthTableBits[$mode][$l];
}
-
+
//----------------------------------------------------------------------
public static function maximumWords($mode, $version)
{
- if($mode == QR_MODE_STRUCTURE)
+ if($mode == QR_MODE_STRUCTURE)
return 3;
-
+
if($version <= 9) {
$l = 0;
} else if($version <= 26) {
@@ -490,7 +490,7 @@
$bits = self::$lengthTableBits[$mode][$l];
$words = (1 << $bits) - 1;
-
+
if($mode == QR_MODE_KANJI) {
$words *= 2; // the number of bytes is required
}
@@ -544,11 +544,11 @@
array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)),
array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)),
array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)),//40
- );
+ );
//----------------------------------------------------------------------
// CACHEABLE!!!
-
+
public static function getEccSpec($version, $level, array &$spec)
{
if (count($spec) < 5) {
@@ -564,7 +564,7 @@
$spec[0] = $b1;
$spec[1] = (int)($data / $b1);
$spec[2] = (int)($ecc / $b1);
- $spec[3] = 0;
+ $spec[3] = 0;
$spec[4] = 0;
} else {
$spec[0] = $b1;
@@ -578,13 +578,13 @@
// Alignment pattern ---------------------------------------------------
// Positions of alignment patterns.
- // This array includes only the second and the third position of the
- // alignment patterns. Rest of them can be calculated from the distance
+ // This array includes only the second and the third position of the
+ // alignment patterns. Rest of them can be calculated from the distance
// between them.
-
+
// See Table 1 in Appendix E (pp.71) of JIS X0510:2004.
-
- public static $alignmentPattern = array(
+
+ public static $alignmentPattern = array(
array( 0, 0),
array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5
array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10
@@ -594,9 +594,9 @@
array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), //26-30
array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), //31-35
array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58), //35-40
- );
+ );
+
-
/** --------------------------------------------------------------------
* Put an alignment marker.
* @param frame
@@ -611,11 +611,11 @@
"\xa1\xa0\xa1\xa0\xa1",
"\xa1\xa0\xa0\xa0\xa1",
"\xa1\xa1\xa1\xa1\xa1"
- );
-
- $yStart = $oy-2;
+ );
+
+ $yStart = $oy-2;
$xStart = $ox-2;
-
+
for($y=0; $y<5; $y++) {
QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]);
}
@@ -663,9 +663,9 @@
// Version information pattern (BCH coded).
// See Table 1 in Appendix D (pp.68) of JIS X0510:2004.
-
+
// size: [QRSPEC_VERSION_MAX - 6]
-
+
public static $versionPattern = array(
0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d,
0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9,
@@ -685,7 +685,7 @@
// Format information --------------------------------------------------
// See calcFormatInfo in tests/test_qrspec.c (orginal qrencode c lib)
-
+
public static $formatInfo = array(
array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976),
array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0),
@@ -697,16 +697,16 @@
{
if($mask < 0 || $mask > 7)
return 0;
-
+
if($level < 0 || $level > 3)
- return 0;
+ return 0;
return self::$formatInfo[$level][$mask];
}
// Frame ---------------------------------------------------------------
// Cache of initial frames.
-
+
public static $frames = array();
/** --------------------------------------------------------------------
@@ -725,8 +725,8 @@
"\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
"\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
"\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
- );
-
+ );
+
for($y=0; $y<7; $y++) {
QRstr::set($frame, $ox, $oy+$y, $finder[$y]);
}
@@ -743,28 +743,28 @@
self::putFinderPattern($frame, 0, 0);
self::putFinderPattern($frame, $width - 7, 0);
self::putFinderPattern($frame, 0, $width - 7);
-
+
// Separator
$yOffset = $width - 7;
-
+
for($y=0; $y<7; $y++) {
$frame[$y][7] = "\xc0";
$frame[$y][$width - 8] = "\xc0";
$frame[$yOffset][7] = "\xc0";
$yOffset++;
}
-
+
$setPattern = str_repeat("\xc0", 8);
-
+
QRstr::set($frame, 0, 7, $setPattern);
QRstr::set($frame, $width-8, 7, $setPattern);
QRstr::set($frame, 0, $width - 8, $setPattern);
-
+
// Format info
$setPattern = str_repeat("\x84", 9);
QRstr::set($frame, 0, 8, $setPattern);
QRstr::set($frame, $width - 8, 8, $setPattern, 8);
-
+
$yOffset = $width - 8;
for($y=0; $y<8; $y++,$yOffset++) {
@@ -772,22 +772,22 @@
$frame[$yOffset][8] = "\x84";
}
- // Timing pattern
-
+ // Timing pattern
+
for($i=1; $i<$width-15; $i++) {
$frame[6][7+$i] = chr(0x90 | ($i & 1));
$frame[7+$i][6] = chr(0x90 | ($i & 1));
}
-
- // Alignment pattern
+
+ // Alignment pattern
self::putAlignmentPattern($version, $frame, $width);
-
- // Version information
+
+ // Version information
if($version >= 7) {
$vinf = self::getVersionPattern($version);
$v = $vinf;
-
+
for($x=0; $x<6; $x++) {
for($y=0; $y<3; $y++) {
$frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
@@ -803,10 +803,10 @@
}
}
}
-
- // and a little bit...
+
+ // and a little bit...
$frame[$width - 8][8] = "\x81";
-
+
return $frame;
}
@@ -814,12 +814,12 @@
public static function debug($frame, $binary_mode = false)
{
if ($binary_mode) {
-
+
foreach ($frame as &$frameLine) {
$frameLine = join(' ', explode('0', $frameLine));
$frameLine = join('██', explode('1', $frameLine));
}
-
+
?>