Browse Source
Possibilité de générer un code QR depuis la barre de recherche, en ajoutant le générateur comme moteur de recherche.pull/10/head

22 changed files with 2624 additions and 2035 deletions
@ -0,0 +1,21 @@ |
|||
<?php |
|||
require "options.inc.php"; |
|||
?> |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"> |
|||
<ShortName>Générer un code QR</ShortName> |
|||
<Description>Générez des codes QR depuis votre barre de recherche ou d'adresse</Description> |
|||
<Image height="16" width="16" type="image/png"><?php echo $cheminInstall; ?>favicons/<?php echo $theme; ?>-16.png</Image> |
|||
<Image height="32" width="32" type="image/png"><?php echo $cheminInstall; ?>favicons/<?php echo $theme; ?>-32.png</Image> |
|||
<Image height="48" width="48" type="image/png"><?php echo $cheminInstall; ?>favicons/<?php echo $theme; ?>-48.png</Image> |
|||
<Image height="64" width="64" type="image/png"><?php echo $cheminInstall; ?>favicons/<?php echo $theme; ?>-64.png</Image> |
|||
<Image height="96" width="96" type="image/png"><?php echo $cheminInstall; ?>favicons/<?php echo $theme; ?>-96.png</Image> |
|||
<Image height="128" width="128" type="image/png"><?php echo $cheminInstall; ?>favicons/<?php echo $theme; ?>-128.png</Image> |
|||
<Image height="192" width="192" type="image/png"><?php echo $cheminInstall; ?>favicons/<?php echo $theme; ?>-192.png</Image> |
|||
<Image height="256" width="256" type="image/png"><?php echo $cheminInstall; ?>favicons/<?php echo $theme; ?>-256.png</Image> |
|||
<Image height="384" width="384" type="image/png"><?php echo $cheminInstall; ?>favicons/<?php echo $theme; ?>-384.png</Image> |
|||
<Image height="512" width="512" type="image/png"><?php echo $cheminInstall; ?>favicons/<?php echo $theme; ?>-512.png</Image> |
|||
<Language>fr</Language> |
|||
<InputEncoding>UTF-8</InputEncoding> |
|||
<Url type="text/html" template="<?php echo $cheminInstall; ?>?texte={searchTerms}"/> |
|||
</OpenSearchDescription> |
@ -0,0 +1,37 @@ |
|||
<?php |
|||
supprimerVieuxQR(60 * 60 * 24 * 7); // Indique le temps en secondes après lequel le code qr sera supprimé quand qq chargera la page |
|||
$theme = "defaut"; // defaut ou parinux |
|||
|
|||
if ($theme == "defaut") { |
|||
$couleurPrincipale = "#2D2F34"; |
|||
} else if ($theme == "parinux") { |
|||
$couleurPrincipale = "#157097"; |
|||
} |
|||
|
|||
$cheminInstall = "http://localhost:8888/qr/"; |
|||
|
|||
|
|||
|
|||
function generateRandomString($length) { |
|||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|||
$charactersLength = strlen($characters); |
|||
$randomString = ''; |
|||
for ($i = 0; $i < $length; $i++) { |
|||
$randomString .= $characters[rand(0, $charactersLength - 1)]; |
|||
} |
|||
return $randomString; |
|||
} |
|||
|
|||
function supprimerVieuxQR($tempsDeSuppression) { |
|||
$listeCodesQR = new DirectoryIterator("temp"); |
|||
foreach($listeCodesQR as $listeCodesQR) { |
|||
if ($listeCodesQR->getFilename() != "." AND $listeCodesQR->getFilename() != "..") { |
|||
if ((time() - filemtime("temp/" . $listeCodesQR->getFilename())) > $tempsDeSuppression) { // Si le temps actuel (en heure Posix) moins la date de dernière modification de l'image est supérieur à la durée de vie demandée de l'image |
|||
unlink("temp/" . $listeCodesQR->getFilename()); // Alors supprimer cette image |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
?> |
@ -0,0 +1,2 @@ |
|||
.idea/ |
|||
temp/*.png |
@ -1,45 +1,61 @@ |
|||
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 |
|||
|
|||
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. |
|||
|
|||
== UPDATE == |
|||
Added support for eps export |
|||
Usage : QRcode::eps('arguments'); |
|||
|
|||
Added support for SVG export |
|||
Usage : QRcode::svg('arguments'); |
|||
|
|||
Added support for color export : |
|||
example : |
|||
$back_color = 0xFFFF00; |
|||
$fore_color = 0xFF00FF; |
|||
QRcode::png('some othertext 1234', false, 'h', 20, 1, false, $back_color, $fore_color); |
|||
|
|||
|
|||
Copyright (C) 2012 by Alexandre Assouad |
|||
|
|||
== 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 |
|||
|
|||
|
@ -1,94 +0,0 @@ |
|||
<?php |
|||
/* |
|||
* PHP QR Code encoder |
|||
* |
|||
* Exemplatory usage |
|||
* |
|||
* 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 |
|||
*/ |
|||
|
|||
echo "<h1>PHP QR Code</h1><hr/>"; |
|||
|
|||
//set it to writable location, a place for temp generated PNG files |
|||
$PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR; |
|||
|
|||
//html PNG location prefix |
|||
$PNG_WEB_DIR = 'temp/'; |
|||
|
|||
include "qrlib.php"; |
|||
|
|||
//ofcourse we need rights to create temp dir |
|||
if (!file_exists($PNG_TEMP_DIR)) |
|||
mkdir($PNG_TEMP_DIR); |
|||
|
|||
|
|||
$filename = $PNG_TEMP_DIR.'test.png'; |
|||
|
|||
//processing form input |
|||
//remember to sanitize user input in real-life solution !!! |
|||
$errorCorrectionLevel = 'L'; |
|||
if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H'))) |
|||
$errorCorrectionLevel = $_REQUEST['level']; |
|||
|
|||
$matrixPointSize = 4; |
|||
if (isset($_REQUEST['size'])) |
|||
$matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10); |
|||
|
|||
|
|||
if (isset($_REQUEST['data'])) { |
|||
|
|||
//it's very important! |
|||
if (trim($_REQUEST['data']) == '') |
|||
die('data cannot be empty! <a href="?">back</a>'); |
|||
|
|||
// user data |
|||
$filename = $PNG_TEMP_DIR.'test'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png'; |
|||
QRcode::png($_REQUEST['data'], $filename, $errorCorrectionLevel, $matrixPointSize, 2); |
|||
|
|||
} else { |
|||
|
|||
//default data |
|||
echo 'You can provide data in GET parameter: <a href="?data=like_that">like that</a><hr/>'; |
|||
QRcode::png('PHP QR Code :)', $filename, $errorCorrectionLevel, $matrixPointSize, 2); |
|||
|
|||
} |
|||
|
|||
//display generated file |
|||
echo '<img src="'.$PNG_WEB_DIR.basename($filename).'" /><hr/>'; |
|||
|
|||
//config form |
|||
echo '<form action="index.php" method="post"> |
|||
Data: <input name="data" value="'.(isset($_REQUEST['data'])?htmlspecialchars($_REQUEST['data']):'PHP QR Code :)').'" /> |
|||
ECC: <select name="level"> |
|||
<option value="L"'.(($errorCorrectionLevel=='L')?' selected':'').'>L - smallest</option> |
|||
<option value="M"'.(($errorCorrectionLevel=='M')?' selected':'').'>M</option> |
|||
<option value="Q"'.(($errorCorrectionLevel=='Q')?' selected':'').'>Q</option> |
|||
<option value="H"'.(($errorCorrectionLevel=='H')?' selected':'').'>H - best</option> |
|||
</select> |
|||
Size: <select name="size">'; |
|||
|
|||
for($i=1;$i<=10;$i++) |
|||
echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>'; |
|||
|
|||
echo '</select> |
|||
<input type="submit" value="GENERATE"></form><hr/>'; |
|||
|
|||
// benchmark |
|||
QRtools::timeBenchmark(); |
|||
|
|||
|
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -1,95 +1,107 @@ |
|||
<?php |
|||
/* |
|||
* PHP QR Code encoder |
|||
* |
|||
* Image output of code using GD2 |
|||
* |
|||
* 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 |
|||
*/ |
|||
|
|||
define('QR_IMAGE', true); |
|||
|
|||
class QRimage { |
|||
|
|||
//---------------------------------------------------------------------- |
|||
public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) |
|||
{ |
|||
$image = self::image($frame, $pixelPerPoint, $outerFrame); |
|||
|
|||
if ($filename === false) { |
|||
Header("Content-type: image/png"); |
|||
ImagePng($image); |
|||
} else { |
|||
if($saveandprint===TRUE){ |
|||
ImagePng($image, $filename); |
|||
header("Content-type: image/png"); |
|||
ImagePng($image); |
|||
}else{ |
|||
ImagePng($image, $filename); |
|||
} |
|||
} |
|||
|
|||
ImageDestroy($image); |
|||
} |
|||
|
|||
//---------------------------------------------------------------------- |
|||
public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) |
|||
{ |
|||
$image = self::image($frame, $pixelPerPoint, $outerFrame); |
|||
|
|||
if ($filename === false) { |
|||
Header("Content-type: image/jpeg"); |
|||
ImageJpeg($image, null, $q); |
|||
} else { |
|||
ImageJpeg($image, $filename, $q); |
|||
} |
|||
|
|||
ImageDestroy($image); |
|||
} |
|||
|
|||
//---------------------------------------------------------------------- |
|||
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) |
|||
{ |
|||
$h = count($frame); |
|||
$w = strlen($frame[0]); |
|||
|
|||
$imgW = $w + 2*$outerFrame; |
|||
$imgH = $h + 2*$outerFrame; |
|||
|
|||
$base_image =ImageCreate($imgW, $imgH); |
|||
|
|||
$col[0] = ImageColorAllocate($base_image,255,255,255); |
|||
$col[1] = ImageColorAllocate($base_image,0,0,0); |
|||
|
|||
imagefill($base_image, 0, 0, $col[0]); |
|||
|
|||
for($y=0; $y<$h; $y++) { |
|||
for($x=0; $x<$w; $x++) { |
|||
if ($frame[$y][$x] == '1') { |
|||
ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); |
|||
} |
|||
} |
|||
} |
|||
|
|||
$target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|||
ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); |
|||
ImageDestroy($base_image); |
|||
|
|||
return $target_image; |
|||
} |
|||
} |
|||
<?php |
|||
/* |
|||
* PHP QR Code encoder |
|||
* |
|||
* Image output of code using GD2 |
|||
* |
|||
* 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 |
|||
*/ |
|||
|
|||
define('QR_IMAGE', true); |
|||
|
|||
class QRimage { |
|||
|
|||
//---------------------------------------------------------------------- |
|||
public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color, $fore_color) |
|||
{ |
|||
$image = self::image($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color); |
|||
|
|||
if ($filename === false) { |
|||
Header("Content-type: image/png"); |
|||
ImagePng($image); |
|||
} else { |
|||
if($saveandprint===TRUE){ |
|||
ImagePng($image, $filename); |
|||
header("Content-type: image/png"); |
|||
ImagePng($image); |
|||
}else{ |
|||
ImagePng($image, $filename); |
|||
} |
|||
} |
|||
|
|||
ImageDestroy($image); |
|||
} |
|||
|
|||
//---------------------------------------------------------------------- |
|||
public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) |
|||
{ |
|||
$image = self::image($frame, $pixelPerPoint, $outerFrame); |
|||
|
|||
if ($filename === false) { |
|||
Header("Content-type: image/jpeg"); |
|||
ImageJpeg($image, null, $q); |
|||
} else { |
|||
ImageJpeg($image, $filename, $q); |
|||
} |
|||
|
|||
ImageDestroy($image); |
|||
} |
|||
|
|||
//---------------------------------------------------------------------- |
|||
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $back_color = 0xFFFFFF, $fore_color = 0x000000) |
|||
{ |
|||
$h = count($frame); |
|||
$w = strlen($frame[0]); |
|||
|
|||
$imgW = $w + 2*$outerFrame; |
|||
$imgH = $h + 2*$outerFrame; |
|||
|
|||
$base_image =ImageCreate($imgW, $imgH); |
|||
|
|||
// convert a hexadecimal color code into decimal format (red = 255 0 0, green = 0 255 0, blue = 0 0 255) |
|||
$r1 = round((($fore_color & 0xFF0000) >> 16), 5); |
|||
$g1 = round((($fore_color & 0x00FF00) >> 8), 5); |
|||
$b1 = round(($fore_color & 0x0000FF), 5); |
|||
|
|||
// convert a hexadecimal color code into decimal format (red = 255 0 0, green = 0 255 0, blue = 0 0 255) |
|||
$r2 = round((($back_color & 0xFF0000) >> 16), 5); |
|||
$g2 = round((($back_color & 0x00FF00) >> 8), 5); |
|||
$b2 = round(($back_color & 0x0000FF), 5); |
|||
|
|||
|
|||
|
|||
$col[0] = ImageColorAllocate($base_image, $r2, $g2, $b2); |
|||
$col[1] = ImageColorAllocate($base_image, $r1, $g1, $b1); |
|||
|
|||
imagefill($base_image, 0, 0, $col[0]); |
|||
|
|||
for($y=0; $y<$h; $y++) { |
|||
for($x=0; $x<$w; $x++) { |
|||
if ($frame[$y][$x] == '1') { |
|||
ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); |
|||
} |
|||
} |
|||
} |
|||
|
|||
$target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|||
ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); |
|||
ImageDestroy($base_image); |
|||
|
|||
return $target_image; |
|||
} |
|||
} |
|||
|
@ -1,43 +1,44 @@ |
|||
<?php |
|||
/* |
|||
* PHP QR Code encoder |
|||
* |
|||
* Root library file, prepares environment and includes dependencies |
|||
* |
|||
* 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> |
|||
* |
|||
* 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 |
|||
*/ |
|||
|
|||
$QR_BASEDIR = dirname(__FILE__).DIRECTORY_SEPARATOR; |
|||
|
|||
// Required libs |
|||
|
|||
include $QR_BASEDIR."qrconst.php"; |
|||
include $QR_BASEDIR."qrconfig.php"; |
|||
include $QR_BASEDIR."qrtools.php"; |
|||
include $QR_BASEDIR."qrspec.php"; |
|||
include $QR_BASEDIR."qrimage.php"; |
|||
include $QR_BASEDIR."qrinput.php"; |
|||
include $QR_BASEDIR."qrbitstream.php"; |
|||
include $QR_BASEDIR."qrsplit.php"; |
|||
include $QR_BASEDIR."qrrscode.php"; |
|||
include $QR_BASEDIR."qrmask.php"; |
|||
include $QR_BASEDIR."qrencode.php"; |
|||
|
|||
<?php |
|||
/* |
|||
* PHP QR Code encoder |
|||
* |
|||
* Root library file, prepares environment and includes dependencies |
|||
* |
|||
* 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> |
|||
* |
|||
* 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 |
|||
*/ |
|||
|
|||
$QR_BASEDIR = dirname(__FILE__).DIRECTORY_SEPARATOR; |
|||
|
|||
// Required libs |
|||
|
|||
include $QR_BASEDIR."qrconst.php"; |
|||
include $QR_BASEDIR."qrconfig.php"; |
|||
include $QR_BASEDIR."qrtools.php"; |
|||
include $QR_BASEDIR."qrspec.php"; |
|||
include $QR_BASEDIR."qrimage.php"; |
|||
include $QR_BASEDIR."qrvect.php"; |
|||
include $QR_BASEDIR."qrinput.php"; |
|||
include $QR_BASEDIR."qrbitstream.php"; |
|||
include $QR_BASEDIR."qrsplit.php"; |
|||
include $QR_BASEDIR."qrrscode.php"; |
|||
include $QR_BASEDIR."qrmask.php"; |
|||
include $QR_BASEDIR."qrencode.php"; |
|||
|
|||
|
@ -1,172 +1,185 @@ |
|||
<?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'); |
|||
<?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; |
|||
} |
|||
|
|||
//---------------------------------------------------------------------- |
|||