Ajout de la recherche OpenSearch

Possibilité de générer un code QR depuis la barre de recherche, en
ajoutant le générateur comme moteur de recherche.
This commit is contained in:
Miraty 2019-03-17 16:03:43 +01:00
parent 9ce259cfa0
commit 8a2a605f45
22 changed files with 2632 additions and 2043 deletions

260
index.php
View File

@ -3,15 +3,8 @@
https://code.antopie.org/miraty/qr https://code.antopie.org/miraty/qr
--> -->
<?php <?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";
}
require "options.inc.php";
?> ?>
@ -34,166 +27,159 @@
<link rel="icon" type="image/png" href="favicons/<?php echo $theme; ?>-512.png" sizes="512x512"/> <link rel="icon" type="image/png" href="favicons/<?php echo $theme; ?>-512.png" sizes="512x512"/>
<meta name="theme-color" content="<?php echo $couleurPrincipale; ?>"> <meta name="theme-color" content="<?php echo $couleurPrincipale; ?>">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="search" type="application/opensearchdescription+xml" title="Générer un code QR" href="opensearch.php" />
<style> <style>
<?php require("lessphp/lessc.inc.php"); <?php require "lessphp/lessc.inc.php";
$less = new lessc; $less = new lessc;
echo $less->compileFile("themes/" . $theme . ".less"); ?> echo $less->compileFile("themes/" . $theme . ".less"); ?>
</style> </style>
</head> </head>
<body lang="fr"> <body lang="fr">
<header>
<a href=""><img id="logo" src="<?php echo $theme; ?>.png" alt="Logo <?php echo $theme; ?>"> <h1>Générateur de codes QR</h1></a>
</header>
<form method="post">
<div class="param"> <?php if (!isset($_GET["texte"])) { // Si OpenSearch n'a pas été utilisé ?>
<label for="texte">Texte à encoder</label>
<br>
<textarea rows="8" required="" id="texte" placeholder="Entrez le texte à encoder dans le code QR" name="texte"><?php
if (isset($_POST['texte'])) {
echo $_POST['texte'];
}
?></textarea> <header>
</div> <a href=""><img id="logo" src="<?php echo $theme; ?>.png" alt="Logo <?php echo $theme; ?>"> <h1>Générateur de codes QR</h1></a>
</header>
<form method="post">
<div id="menusDeroulants">
<div class="param"> <div class="param">
<label for="taille">Taille de l'image</label> <label for="texte">Texte à encoder</label>
<span class="conteneurAide"> <span class="conteneurAide">
<img src="aide.svg" alt="Aide"> <img src="aide.svg" alt="Aide">
<span class="contenuAide">Par combien les dimensions de l'image seront-elles multipliées ?</span> <span class="contenuAide">Vous pouvez encoder ce que vous voulez sous forme de texte.</span>
</span> </span>
<br> <br>
<select id="taille" name="taille"> <textarea rows="8" required="" id="texte" placeholder="Entrez le texte à encoder dans le code QR" name="texte"><?php
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 1)) {echo 'selected="" ';} ?>value="1">1</option>
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 2)) {echo 'selected="" ';} ?>value="2">2</option> if (isset($_POST['texte'])) {
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 3)) {echo 'selected="" ';} ?>value="3">3</option> echo $_POST['texte'];
<option <?php if ((isset($_POST['taille']) AND ($_POST['taille'] == 4)) OR (!isset($_POST['taille']))) {echo 'selected="" ';} ?>value="4">4 - par défaut</option> }
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 5)) {echo 'selected="" ';} ?>value="5">5</option>
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 6)) {echo 'selected="" ';} ?>value="6">6</option> ?></textarea>
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 7)) {echo 'selected="" ';} ?>value="7">7</option>
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 8)) {echo 'selected="" ';} ?>value="8">8</option>
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 9)) {echo 'selected="" ';} ?>value="9">9</option>
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 10)) {echo 'selected="" ';} ?>value="10">10</option>
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 20)) {echo 'selected="" ';} ?>value="20">20</option>
</select>
</div> </div>
<div class="param"> <div id="menusDeroulants">
<label for="redondance">Taux de redondance</label> <div class="param">
<label for="taille">Taille de l'image</label>
<span class="conteneurAide">
<img src="aide.svg" alt="Aide">
<span class="contenuAide">Par combien les dimensions de l'image seront-elles multipliées ?</span>
</span>
<br>
<select id="taille" name="taille">
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 1)) {echo 'selected="" ';} ?>value="1">1</option>
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 2)) {echo 'selected="" ';} ?>value="2">2</option>
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 3)) {echo 'selected="" ';} ?>value="3">3</option>
<option <?php if ((isset($_POST['taille']) AND ($_POST['taille'] == 4)) OR (!isset($_POST['taille']))) {echo 'selected="" ';} ?>value="4">4 - par défaut</option>
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 5)) {echo 'selected="" ';} ?>value="5">5</option>
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 6)) {echo 'selected="" ';} ?>value="6">6</option>
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 7)) {echo 'selected="" ';} ?>value="7">7</option>
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 8)) {echo 'selected="" ';} ?>value="8">8</option>
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 9)) {echo 'selected="" ';} ?>value="9">9</option>
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 10)) {echo 'selected="" ';} ?>value="10">10</option>
<option <?php if (isset($_POST['taille']) AND ($_POST['taille'] == 20)) {echo 'selected="" ';} ?>value="20">20</option>
</select>
</div>
<span class="conteneurAide"> <div class="param">
<img src="aide.svg" alt="Aide"> <label for="redondance">Taux de redondance</label>
<span class="contenuAide">La redondance est le "doublement" des informations dans le code QR afin de corriger les erreurs lors du décodage. Un taux plus élevé produira un code QR plus grand, mais aura plus de chance d'être décodé correctement.</span>
</span> <span class="conteneurAide">
<img src="aide.svg" alt="Aide">
<span class="contenuAide">La redondance est le "doublement" des informations dans le code QR afin de corriger les erreurs lors du décodage. Un taux plus élevé produira un code QR plus grand, mais aura plus de chance d'être décodé correctement.</span>
</span>
<br>
<select id="redondance" name="redondance">
<option <?php if (isset($_POST['redondance']) AND ($_POST['redondance'] == "L")) {echo 'selected="" ';} ?>value="L">L - 7% de redondance</option>
<option <?php if (isset($_POST['redondance']) AND ($_POST['redondance'] == "M")) {echo 'selected="" ';} ?>value="M">M - 15% de redondance</option>
<option <?php if (isset($_POST['redondance']) AND ($_POST['redondance'] == "Q")) {echo 'selected="" ';} ?>value="Q">Q - 25% de redondance</option>
<option <?php if ((isset($_POST['redondance']) AND ($_POST['redondance'] == "H")) OR (!isset($_POST['redondance']))) {echo 'selected="" ';} ?>value="H">H - 30% de redondance</option>
</select>
</div>
<div class="param">
<label for="marge">Taille de la marge</label>
<span class="conteneurAide">
<img src="aide.svg" alt="Aide">
<span class="contenuAide">Nombre de pixels des bandes blanches autour du code QR.</span>
</span>
<br>
<select id="marge" name="marge">
<option <?php if (isset($_POST['marge']) AND ($_POST['marge'] == "0")) {echo 'selected="" ';} ?>value="0">0</option>
<option <?php if (isset($_POST['marge']) AND ($_POST['marge'] == "1")) {echo 'selected="" ';} ?>value="1">1</option>
<option <?php if ((isset($_POST['marge']) AND ($_POST['marge'] == "2")) OR (!isset($_POST['marge']))) {echo 'selected="" ';} ?>value="2">2 - par défaut</option>
<option <?php if (isset($_POST['marge']) AND ($_POST['marge'] == "3")) {echo 'selected="" ';} ?>value="3">3</option>
<option <?php if (isset($_POST['marge']) AND ($_POST['marge'] == "5")) {echo 'selected="" ';} ?>value="5">5</option>
<option <?php if (isset($_POST['marge']) AND ($_POST['marge'] == "10")) {echo 'selected="" ';} ?>value="10">10</option>
</select>
</div>
<br>
<select id="redondance" name="redondance">
<option <?php if (isset($_POST['redondance']) AND ($_POST['redondance'] == "L")) {echo 'selected="" ';} ?>value="L">L - 7% de redondance</option>
<option <?php if (isset($_POST['redondance']) AND ($_POST['redondance'] == "M")) {echo 'selected="" ';} ?>value="M">M - 15% de redondance</option>
<option <?php if (isset($_POST['redondance']) AND ($_POST['redondance'] == "Q")) {echo 'selected="" ';} ?>value="Q">Q - 25% de redondance</option>
<option <?php if ((isset($_POST['redondance']) AND ($_POST['redondance'] == "H")) OR (!isset($_POST['redondance']))) {echo 'selected="" ';} ?>value="H">H - 30% de redondance</option>
</select>
</div> </div>
<br/>
<div class="param"> <div class="centrer">
<label for="marge">Taille de la marge</label> <input type="submit" value="Générer" />
<span class="conteneurAide">
<img src="aide.svg" alt="Aide">
<span class="contenuAide">Nombre de pixels des bandes blanches autour du code QR.</span>
</span>
<br>
<select id="marge" name="marge">
<option <?php if (isset($_POST['marge']) AND ($_POST['marge'] == "0")) {echo 'selected="" ';} ?>value="0">0</option>
<option <?php if (isset($_POST['marge']) AND ($_POST['marge'] == "1")) {echo 'selected="" ';} ?>value="1">1</option>
<option <?php if ((isset($_POST['marge']) AND ($_POST['marge'] == "2")) OR (!isset($_POST['marge']))) {echo 'selected="" ';} ?>value="2">2 - par défaut</option>
<option <?php if (isset($_POST['marge']) AND ($_POST['marge'] == "3")) {echo 'selected="" ';} ?>value="3">3</option>
<option <?php if (isset($_POST['marge']) AND ($_POST['marge'] == "5")) {echo 'selected="" ';} ?>value="5">5</option>
<option <?php if (isset($_POST['marge']) AND ($_POST['marge'] == "10")) {echo 'selected="" ';} ?>value="10">10</option>
</select>
</div> </div>
<br/>
</div> <br/>
<br/>
<div class="centrer">
<input type="submit" value="Générer" />
</div>
<br/>
<br/>
</form>
<?php
function generateRandomString($length) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
if (isset($_POST['texte']) and isset($_POST['taille']) and isset($_POST['redondance']) and isset($_POST['marge'])) {
include "phpqrcode/qrlib.php";
$cheminImage = "temp/" . generateRandomString(50) . ".png";
QRcode::png($_POST['texte'], $cheminImage, $_POST['redondance'], $_POST['taille'], $_POST['marge']); ?>
<div class="centrer">
<a href="<?php echo $cheminImage; ?>" class="bouton" download="<?php echo $_POST['texte']; ?>.png">Télécharger ce code QR</a>
</div>
<br><br>
<div class="centrer">
<a href="<?php echo $cheminImage; ?>"><img id="codeQR" src="<?php echo $cheminImage; ?>"/></a>
</div>
<?php
}
?>
<footer>
<a class="lienCodeSource" href="https://code.antopie.org/miraty/qr">Code source</a>
</footer>
</body>
</form>
<?php <?php
function supprimerVieuxQR($tempsDeSuppression) { if (isset($_POST['texte']) and isset($_POST['taille']) and isset($_POST['redondance']) and isset($_POST['marge'])) {
require "phpqrcode/qrlib.php";
$listeCodesQR = new DirectoryIterator("temp");
foreach($listeCodesQR as $listeCodesQR) {
if ($listeCodesQR->getFilename() != "." AND $listeCodesQR->getFilename() != "..") {
if ((time() - filemtime("temp/" . $listeCodesQR->getFilename())) > $tempsDeSuppression) {
unlink("temp/" . $listeCodesQR->getFilename());
}
}
$cheminImage = "temp/" . generateRandomString(50) . ".png";
QRcode::png($_POST['texte'], $cheminImage, $_POST['redondance'], $_POST['taille'], $_POST['marge']); ?>
<div class="centrer">
<a href="<?php echo $cheminImage; ?>" class="bouton" download="<?php echo htmlspecialchars($_POST['texte']); ?>.png">Télécharger ce code QR</a>
</div>
<br><br>
<div class="centrer">
<a href="<?php echo $cheminImage; ?>"><img alt='Un code QR contenant "<?php echo htmlspecialchars($_GET['texte']); ?>"' id="codeQR" src="<?php echo $cheminImage; ?>"/></a>
</div>
<?php
} }
?>
} <footer>
<a class="lienCodeSource" href="https://code.antopie.org/miraty/qr">Code source</a>
</footer>
?> <?php } else if (isset($_GET["texte"])) { // Si OpenSearch a été utilisé
if (empty($_GET["texte"])) { // Si rien n'a été recherché ?>
<span style="font-size: 30px;">Erreur : vous ne pouvez pas générer un code QR vide !
<?php } else if (!empty($_GET["texte"])) {
require "phpqrcode/qrlib.php";
$cheminImage = "temp/" . generateRandomString(50) . ".png";
QRcode::png($_GET['texte'], $cheminImage, "H", 4, 2); ?>
<div class="centrer">
<a href="<?php echo $cheminImage; ?>" class="bouton" download="<?php echo htmlspecialchars($_GET['texte']); ?>.png">Télécharger ce code QR</a>
</div>
<br><br>
<div class="centrer">
<a href="<?php echo $cheminImage; ?>"><img alt='Un code QR contenant "<?php echo htmlspecialchars($_GET['texte']); ?>"' id="codeQR" src="<?php echo $cheminImage; ?>"/></a>
</div>
<?php } } ?>
</body>
</html>

21
opensearch.php Executable file
View File

@ -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>

37
options.inc.php Executable file
View File

@ -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
}
}
}
}
?>

2
phpqrcode/.gitignore vendored Executable file
View File

@ -0,0 +1,2 @@
.idea/
temp/*.png

View File

@ -18,7 +18,7 @@ provided comments and project wiki page (links in README file)
Notice: probably you should'nt use all of this in same script :) Notice: probably you should'nt use all of this in same script :)
<?phpb <?php
//include only that one, rest required files will be included from it //include only that one, rest required files will be included from it
include "qrlib.php" include "qrlib.php"

View File

@ -1,45 +1,61 @@
This is PHP implementation of QR Code 2-D barcode generator. It is pure-php 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. LGPL-licensed implementation based on C libqrencode by Kentaro Fukuchi.
== LICENSING == == UPDATE ==
Added support for eps export
Copyright (C) 2010 by Dominik Dzienia Usage : QRcode::eps('arguments');
This library is free software; you can redistribute it and/or modify it under Added support for SVG export
the terms of the GNU Lesser General Public License as published by the Free Usage : QRcode::svg('arguments');
Software Foundation; either version 3 of the License, or any later version.
Added support for color export :
This library is distributed in the hope that it will be useful, but WITHOUT ANY example :
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A $back_color = 0xFFFF00;
PARTICULAR PURPOSE. See the GNU Lesser General Public License (LICENSE file) $fore_color = 0xFF00FF;
for more details. QRcode::png('some othertext 1234', false, 'h', 20, 1, false, $back_color, $fore_color);
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 Copyright (C) 2012 by Alexandre Assouad
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
== LICENSING ==
== INSTALATION AND USAGE ==
Copyright (C) 2010 by Dominik Dzienia
* INSTALL file
* http://sourceforge.net/apps/mediawiki/phpqrcode/index.php?title=Main_Page 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
== CONTACT == Software Foundation; either version 3 of the License, or any later version.
Fell free to contact me via e-mail (deltalab at poczta dot fm) or using This library is distributed in the hope that it will be useful, but WITHOUT ANY
folowing project pages: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License (LICENSE file)
* http://sourceforge.net/projects/phpqrcode/ for more details.
* http://phpqrcode.sourceforge.net/
You should have received a copy of the GNU Lesser General Public License along
== ACKNOWLEDGMENTS == with this library; if not, write to the Free Software Foundation, Inc., 51
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Based on C libqrencode library (ver. 3.1.1)
Copyright (C) 2006-2010 by Kentaro Fukuchi == INSTALATION AND USAGE ==
http://megaui.net/fukuchi/works/qrencode/index.en.html
* INSTALL file
QR Code is registered trademarks of DENSO WAVE INCORPORATED in JAPAN and other * http://sourceforge.net/apps/mediawiki/phpqrcode/index.php?title=Main_Page
countries.
== CONTACT ==
Reed-Solomon code encoder is written by Phil Karn, KA9Q.
Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q 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

View File

@ -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:&nbsp;<input name="data" value="'.(isset($_REQUEST['data'])?htmlspecialchars($_REQUEST['data']):'PHP QR Code :)').'" />&nbsp;
ECC:&nbsp;<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>&nbsp;
Size:&nbsp;<select name="size">';
for($i=1;$i<=10;$i++)
echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>';
echo '</select>&nbsp;
<input type="submit" value="GENERATE"></form><hr/>';
// benchmark
QRtools::timeBenchmark();

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,95 +1,107 @@
<?php <?php
/* /*
* PHP QR Code encoder * PHP QR Code encoder
* *
* Image output of code using GD2 * Image output of code using GD2
* *
* PHP QR Code is distributed under LGPL 3 * PHP QR Code is distributed under LGPL 3
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm> * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 3 of the License, or any later version. * version 3 of the License, or any later version.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
define('QR_IMAGE', true); define('QR_IMAGE', true);
class QRimage { class QRimage {
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color, $fore_color)
{ {
$image = self::image($frame, $pixelPerPoint, $outerFrame); $image = self::image($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color);
if ($filename === false) { if ($filename === false) {
Header("Content-type: image/png"); Header("Content-type: image/png");
ImagePng($image); ImagePng($image);
} else { } else {
if($saveandprint===TRUE){ if($saveandprint===TRUE){
ImagePng($image, $filename); ImagePng($image, $filename);
header("Content-type: image/png"); header("Content-type: image/png");
ImagePng($image); ImagePng($image);
}else{ }else{
ImagePng($image, $filename); ImagePng($image, $filename);
} }
} }
ImageDestroy($image); ImageDestroy($image);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85)
{ {
$image = self::image($frame, $pixelPerPoint, $outerFrame); $image = self::image($frame, $pixelPerPoint, $outerFrame);
if ($filename === false) { if ($filename === false) {
Header("Content-type: image/jpeg"); Header("Content-type: image/jpeg");
ImageJpeg($image, null, $q); ImageJpeg($image, null, $q);
} else { } else {
ImageJpeg($image, $filename, $q); ImageJpeg($image, $filename, $q);
} }
ImageDestroy($image); ImageDestroy($image);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $back_color = 0xFFFFFF, $fore_color = 0x000000)
{ {
$h = count($frame); $h = count($frame);
$w = strlen($frame[0]); $w = strlen($frame[0]);
$imgW = $w + 2*$outerFrame; $imgW = $w + 2*$outerFrame;
$imgH = $h + 2*$outerFrame; $imgH = $h + 2*$outerFrame;
$base_image =ImageCreate($imgW, $imgH); $base_image =ImageCreate($imgW, $imgH);
$col[0] = ImageColorAllocate($base_image,255,255,255); // convert a hexadecimal color code into decimal format (red = 255 0 0, green = 0 255 0, blue = 0 0 255)
$col[1] = ImageColorAllocate($base_image,0,0,0); $r1 = round((($fore_color & 0xFF0000) >> 16), 5);
$g1 = round((($fore_color & 0x00FF00) >> 8), 5);
imagefill($base_image, 0, 0, $col[0]); $b1 = round(($fore_color & 0x0000FF), 5);
for($y=0; $y<$h; $y++) { // convert a hexadecimal color code into decimal format (red = 255 0 0, green = 0 255 0, blue = 0 0 255)
for($x=0; $x<$w; $x++) { $r2 = round((($back_color & 0xFF0000) >> 16), 5);
if ($frame[$y][$x] == '1') { $g2 = round((($back_color & 0x00FF00) >> 8), 5);
ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); $b2 = round(($back_color & 0x0000FF), 5);
}
}
}
$col[0] = ImageColorAllocate($base_image, $r2, $g2, $b2);
$target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); $col[1] = ImageColorAllocate($base_image, $r1, $g1, $b1);
ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
ImageDestroy($base_image); imagefill($base_image, 0, 0, $col[0]);
return $target_image; 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;
}
}

View File

@ -45,7 +45,6 @@
if(!QRinput::check($mode, $size, $setData)) { if(!QRinput::check($mode, $size, $setData)) {
throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData)); throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData));
return null;
} }
$this->mode = $mode; $this->mode = $mode;
@ -283,7 +282,6 @@
{ {
if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) { if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) {
throw new Exception('Invalid version no'); throw new Exception('Invalid version no');
return NULL;
} }
$this->version = $version; $this->version = $version;
@ -620,7 +618,6 @@
$ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
if($ver < 0) { if($ver < 0) {
throw new Exception('WRONG VERSION'); throw new Exception('WRONG VERSION');
return -1;
} else if($ver > $this->getVersion()) { } else if($ver > $this->getVersion()) {
$this->setVersion($ver); $this->setVersion($ver);
} else { } else {

View File

@ -1,43 +1,44 @@
<?php <?php
/* /*
* PHP QR Code encoder * PHP QR Code encoder
* *
* Root library file, prepares environment and includes dependencies * Root library file, prepares environment and includes dependencies
* *
* Based on libqrencode C library distributed under LGPL 2.1 * Based on libqrencode C library distributed under LGPL 2.1
* Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net> * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
* *
* PHP QR Code is distributed under LGPL 3 * PHP QR Code is distributed under LGPL 3
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm> * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 3 of the License, or any later version. * version 3 of the License, or any later version.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
$QR_BASEDIR = dirname(__FILE__).DIRECTORY_SEPARATOR; $QR_BASEDIR = dirname(__FILE__).DIRECTORY_SEPARATOR;
// Required libs // Required libs
include $QR_BASEDIR."qrconst.php"; include $QR_BASEDIR."qrconst.php";
include $QR_BASEDIR."qrconfig.php"; include $QR_BASEDIR."qrconfig.php";
include $QR_BASEDIR."qrtools.php"; include $QR_BASEDIR."qrtools.php";
include $QR_BASEDIR."qrspec.php"; include $QR_BASEDIR."qrspec.php";
include $QR_BASEDIR."qrimage.php"; include $QR_BASEDIR."qrimage.php";
include $QR_BASEDIR."qrinput.php"; include $QR_BASEDIR."qrvect.php";
include $QR_BASEDIR."qrbitstream.php"; include $QR_BASEDIR."qrinput.php";
include $QR_BASEDIR."qrsplit.php"; include $QR_BASEDIR."qrbitstream.php";
include $QR_BASEDIR."qrrscode.php"; include $QR_BASEDIR."qrsplit.php";
include $QR_BASEDIR."qrmask.php"; include $QR_BASEDIR."qrrscode.php";
include $QR_BASEDIR."qrencode.php"; include $QR_BASEDIR."qrmask.php";
include $QR_BASEDIR."qrencode.php";

View File

@ -24,22 +24,22 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
define('N1', 3); define('N1', 3);
define('N2', 3); define('N2', 3);
define('N3', 40); define('N3', 40);
define('N4', 10); define('N4', 10);
class QRmask { class QRmask {
public $runLength = array(); public $runLength = array();
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public function __construct() public function __construct()
{ {
$this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0); $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public function writeFormatInformation($width, &$frame, $mask, $level) public function writeFormatInformation($width, &$frame, $mask, $level)
{ {
@ -53,7 +53,7 @@
} else { } else {
$v = 0x84; $v = 0x84;
} }
$frame[8][$width - 1 - $i] = chr($v); $frame[8][$width - 1 - $i] = chr($v);
if($i < 6) { if($i < 6) {
$frame[$i][8] = chr($v); $frame[$i][8] = chr($v);
@ -62,7 +62,7 @@
} }
$format = $format >> 1; $format = $format >> 1;
} }
for($i=0; $i<7; $i++) { for($i=0; $i<7; $i++) {
if($format & 1) { if($format & 1) {
$blacks += 2; $blacks += 2;
@ -70,20 +70,20 @@
} else { } else {
$v = 0x84; $v = 0x84;
} }
$frame[$width - 7 + $i][8] = chr($v); $frame[$width - 7 + $i][8] = chr($v);
if($i == 0) { if($i == 0) {
$frame[8][7] = chr($v); $frame[8][7] = chr($v);
} else { } else {
$frame[8][6 - $i] = chr($v); $frame[8][6 - $i] = chr($v);
} }
$format = $format >> 1; $format = $format >> 1;
} }
return $blacks; return $blacks;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public function mask0($x, $y) { return ($x+$y)&1; } public function mask0($x, $y) { return ($x+$y)&1; }
public function mask1($x, $y) { return ($y&1); } public function mask1($x, $y) { return ($y&1); }
@ -93,12 +93,12 @@
public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3; } public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3; }
public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1; } public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1; }
public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1; } public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
private function generateMaskNo($maskNo, $width, $frame) private function generateMaskNo($maskNo, $width, $frame)
{ {
$bitMask = array_fill(0, $width, array_fill(0, $width, 0)); $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
for($y=0; $y<$width; $y++) { for($y=0; $y<$width; $y++) {
for($x=0; $x<$width; $x++) { for($x=0; $x<$width; $x++) {
if(ord($frame[$y][$x]) & 0x80) { if(ord($frame[$y][$x]) & 0x80) {
@ -107,42 +107,42 @@
$maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y); $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y);
$bitMask[$y][$x] = ($maskFunc == 0)?1:0; $bitMask[$y][$x] = ($maskFunc == 0)?1:0;
} }
} }
} }
return $bitMask; return $bitMask;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public static function serial($bitFrame) public static function serial($bitFrame)
{ {
$codeArr = array(); $codeArr = array();
foreach ($bitFrame as $line) foreach ($bitFrame as $line)
$codeArr[] = join('', $line); $codeArr[] = join('', $line);
return gzcompress(join("\n", $codeArr), 9); return gzcompress(join("\n", $codeArr), 9);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public static function unserial($code) public static function unserial($code)
{ {
$codeArr = array(); $codeArr = array();
$codeLines = explode("\n", gzuncompress($code)); $codeLines = explode("\n", gzuncompress($code));
foreach ($codeLines as $line) foreach ($codeLines as $line)
$codeArr[] = str_split($line); $codeArr[] = str_split($line);
return $codeArr; return $codeArr;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false) public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false)
{ {
$b = 0; $b = 0;
$bitMask = array(); $bitMask = array();
$fileName = QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat'; $fileName = QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat';
if (QR_CACHEABLE) { if (QR_CACHEABLE) {
@ -160,7 +160,7 @@
if ($maskGenOnly) if ($maskGenOnly)
return; return;
$d = $s; $d = $s;
for($y=0; $y<$width; $y++) { for($y=0; $y<$width; $y++) {
@ -174,24 +174,24 @@
return $b; return $b;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public function makeMask($width, $frame, $maskNo, $level) public function makeMask($width, $frame, $maskNo, $level)
{ {
$masked = array_fill(0, $width, str_repeat("\0", $width)); $masked = array_fill(0, $width, str_repeat("\0", $width));
$this->makeMaskNo($maskNo, $width, $frame, $masked); $this->makeMaskNo($maskNo, $width, $frame, $masked);
$this->writeFormatInformation($width, $masked, $maskNo, $level); $this->writeFormatInformation($width, $masked, $maskNo, $level);
return $masked; return $masked;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public function calcN1N3($length) public function calcN1N3($length)
{ {
$demerit = 0; $demerit = 0;
for($i=0; $i<$length; $i++) { for($i=0; $i<$length; $i++) {
if($this->runLength[$i] >= 5) { if($this->runLength[$i] >= 5) {
$demerit += (N1 + ($this->runLength[$i] - 5)); $demerit += (N1 + ($this->runLength[$i] - 5));
} }
@ -213,7 +213,7 @@
} }
return $demerit; return $demerit;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public function evaluateSymbol($width, $frame) public function evaluateSymbol($width, $frame)
{ {
@ -223,18 +223,18 @@
for($y=0; $y<$width; $y++) { for($y=0; $y<$width; $y++) {
$head = 0; $head = 0;
$this->runLength[0] = 1; $this->runLength[0] = 1;
$frameY = $frame[$y]; $frameY = $frame[$y];
if ($y>0) if ($y>0)
$frameYM = $frame[$y-1]; $frameYM = $frame[$y-1];
for($x=0; $x<$width; $x++) { for($x=0; $x<$width; $x++) {
if(($x > 0) && ($y > 0)) { if(($x > 0) && ($y > 0)) {
$b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]);
$w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]);
if(($b22 | ($w22 ^ 1))&1) { if(($b22 | ($w22 ^ 1))&1) {
$demerit += N2; $demerit += N2;
} }
} }
@ -251,14 +251,14 @@
} }
} }
} }
$demerit += $this->calcN1N3($head+1); $demerit += $this->calcN1N3($head+1);
} }
for($x=0; $x<$width; $x++) { for($x=0; $x<$width; $x++) {
$head = 0; $head = 0;
$this->runLength[0] = 1; $this->runLength[0] = 1;
for($y=0; $y<$width; $y++) { for($y=0; $y<$width; $y++) {
if($y == 0 && (ord($frame[$y][$x]) & 1)) { if($y == 0 && (ord($frame[$y][$x]) & 1)) {
$this->runLength[0] = -1; $this->runLength[0] = -1;
@ -273,36 +273,36 @@
} }
} }
} }
$demerit += $this->calcN1N3($head+1); $demerit += $this->calcN1N3($head+1);
} }
return $demerit; return $demerit;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public function mask($width, $frame, $level) public function mask($width, $frame, $level)
{ {
$minDemerit = PHP_INT_MAX; $minDemerit = PHP_INT_MAX;
$bestMaskNum = 0; $bestMaskNum = 0;
$bestMask = array(); $bestMask = array();
$checked_masks = array(0,1,2,3,4,5,6,7); $checked_masks = array(0,1,2,3,4,5,6,7);
if (QR_FIND_FROM_RANDOM !== false) { if (QR_FIND_FROM_RANDOM !== false) {
$howManuOut = 8-(QR_FIND_FROM_RANDOM % 9); $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9);
for ($i = 0; $i < $howManuOut; $i++) { for ($i = 0; $i < $howManuOut; $i++) {
$remPos = rand (0, count($checked_masks)-1); $remPos = rand (0, count($checked_masks)-1);
unset($checked_masks[$remPos]); unset($checked_masks[$remPos]);
$checked_masks = array_values($checked_masks); $checked_masks = array_values($checked_masks);
} }
} }
$bestMask = $frame; $bestMask = $frame;
foreach($checked_masks as $i) { foreach($checked_masks as $i) {
$mask = array_fill(0, $width, str_repeat("\0", $width)); $mask = array_fill(0, $width, str_repeat("\0", $width));
@ -313,16 +313,16 @@
$blacks = (int)(100 * $blacks / ($width * $width)); $blacks = (int)(100 * $blacks / ($width * $width));
$demerit = (int)((int)(abs($blacks - 50) / 5) * N4); $demerit = (int)((int)(abs($blacks - 50) / 5) * N4);
$demerit += $this->evaluateSymbol($width, $mask); $demerit += $this->evaluateSymbol($width, $mask);
if($demerit < $minDemerit) { if($demerit < $minDemerit) {
$minDemerit = $demerit; $minDemerit = $demerit;
$bestMask = $mask; $bestMask = $mask;
$bestMaskNum = $i; $bestMaskNum = $i;
} }
} }
return $bestMask; return $bestMask;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
} }

View File

@ -13,7 +13,7 @@
* The following data / specifications are taken from * The following data / specifications are taken from
* "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004) * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004)
* or * or
* "Automatic identification and data capture techniques -- * "Automatic identification and data capture techniques --
* QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006) * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006)
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
@ -37,46 +37,46 @@
public $modeHint; public $modeHint;
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public function __construct($dataStr, $input, $modeHint) public function __construct($dataStr, $input, $modeHint)
{ {
$this->dataStr = $dataStr; $this->dataStr = $dataStr;
$this->input = $input; $this->input = $input;
$this->modeHint = $modeHint; $this->modeHint = $modeHint;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public static function isdigitat($str, $pos) public static function isdigitat($str, $pos)
{ {
if ($pos >= strlen($str)) if ($pos >= strlen($str))
return false; return false;
return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public static function isalnumat($str, $pos) public static function isalnumat($str, $pos)
{ {
if ($pos >= strlen($str)) if ($pos >= strlen($str))
return false; return false;
return (QRinput::lookAnTable(ord($str[$pos])) >= 0); return (QRinput::lookAnTable(ord($str[$pos])) >= 0);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public function identifyMode($pos) public function identifyMode($pos)
{ {
if ($pos >= strlen($this->dataStr)) if ($pos >= strlen($this->dataStr))
return QR_MODE_NUL; return QR_MODE_NUL;
$c = $this->dataStr[$pos]; $c = $this->dataStr[$pos];
if(self::isdigitat($this->dataStr, $pos)) { if(self::isdigitat($this->dataStr, $pos)) {
return QR_MODE_NUM; return QR_MODE_NUM;
} else if(self::isalnumat($this->dataStr, $pos)) { } else if(self::isalnumat($this->dataStr, $pos)) {
return QR_MODE_AN; return QR_MODE_AN;
} else if($this->modeHint == QR_MODE_KANJI) { } else if($this->modeHint == QR_MODE_KANJI) {
if ($pos+1 < strlen($this->dataStr)) if ($pos+1 < strlen($this->dataStr))
{ {
$d = $this->dataStr[$pos+1]; $d = $this->dataStr[$pos+1];
$word = (ord($c) << 8) | ord($d); $word = (ord($c) << 8) | ord($d);
@ -87,8 +87,8 @@
} }
return QR_MODE_8; return QR_MODE_8;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public function eatNum() public function eatNum()
{ {
@ -98,10 +98,10 @@
while(self::isdigitat($this->dataStr, $p)) { while(self::isdigitat($this->dataStr, $p)) {
$p++; $p++;
} }
$run = $p; $run = $p;
$mode = $this->identifyMode($p); $mode = $this->identifyMode($p);
if($mode == QR_MODE_8) { if($mode == QR_MODE_8) {
$dif = QRinput::estimateBitsModeNum($run) + 4 + $ln $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln
+ QRinput::estimateBitsMode8(1) // + 4 + l8 + QRinput::estimateBitsMode8(1) // + 4 + l8
@ -118,14 +118,14 @@
return $this->eatAn(); return $this->eatAn();
} }
} }
$ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr));
if($ret < 0) if($ret < 0)
return -1; return -1;
return $run; return $run;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public function eatAn() public function eatAn()
{ {
@ -133,18 +133,18 @@
$ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
$p = 0; $p = 0;
while(self::isalnumat($this->dataStr, $p)) { while(self::isalnumat($this->dataStr, $p)) {
if(self::isdigitat($this->dataStr, $p)) { if(self::isdigitat($this->dataStr, $p)) {
$q = $p; $q = $p;
while(self::isdigitat($this->dataStr, $q)) { while(self::isdigitat($this->dataStr, $q)) {
$q++; $q++;
} }
$dif = QRinput::estimateBitsModeAn($p) // + 4 + la $dif = QRinput::estimateBitsModeAn($p) // + 4 + la
+ QRinput::estimateBitsModeNum($q - $p) + 4 + $ln + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln
- QRinput::estimateBitsModeAn($q); // - 4 - la - QRinput::estimateBitsModeAn($q); // - 4 - la
if($dif < 0) { if($dif < 0) {
break; break;
} else { } else {
@ -172,21 +172,21 @@
return $run; return $run;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public function eatKanji() public function eatKanji()
{ {
$p = 0; $p = 0;
while($this->identifyMode($p) == QR_MODE_KANJI) { while($this->identifyMode($p) == QR_MODE_KANJI) {
$p += 2; $p += 2;
} }
$ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr));
if($ret < 0) if($ret < 0)
return -1; return -1;
return $run; return $ret;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -197,9 +197,9 @@
$p = 1; $p = 1;
$dataStrLen = strlen($this->dataStr); $dataStrLen = strlen($this->dataStr);
while($p < $dataStrLen) { while($p < $dataStrLen) {
$mode = $this->identifyMode($p); $mode = $this->identifyMode($p);
if($mode == QR_MODE_KANJI) { if($mode == QR_MODE_KANJI) {
break; break;
@ -237,7 +237,7 @@
$run = $p; $run = $p;
$ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr));
if($ret < 0) if($ret < 0)
return -1; return -1;
@ -253,22 +253,22 @@
return 0; return 0;
$mode = $this->identifyMode(0); $mode = $this->identifyMode(0);
switch ($mode) { switch ($mode) {
case QR_MODE_NUM: $length = $this->eatNum(); break; case QR_MODE_NUM: $length = $this->eatNum(); break;
case QR_MODE_AN: $length = $this->eatAn(); break; case QR_MODE_AN: $length = $this->eatAn(); break;
case QR_MODE_KANJI: case QR_MODE_KANJI:
if ($hint == QR_MODE_KANJI) if ($mode == QR_MODE_KANJI)
$length = $this->eatKanji(); $length = $this->eatKanji();
else $length = $this->eat8(); else $length = $this->eat8();
break; break;
default: $length = $this->eat8(); break; default: $length = $this->eat8(); break;
} }
if($length == 0) return 0; if($length == 0) return 0;
if($length < 0) return -1; if($length < 0) return -1;
$this->dataStr = substr($this->dataStr, $length); $this->dataStr = substr($this->dataStr, $length);
} }
} }
@ -278,9 +278,9 @@
{ {
$stringLen = strlen($this->dataStr); $stringLen = strlen($this->dataStr);
$p = 0; $p = 0;
while ($p<$stringLen) { while ($p<$stringLen) {
$mode = self::identifyMode(substr($this->dataStr, $p), $this->modeHint); $mode = self::identifyMode(substr($this->dataStr, $p));
if($mode == QR_MODE_KANJI) { if($mode == QR_MODE_KANJI) {
$p += 2; $p += 2;
} else { } else {
@ -302,10 +302,10 @@
} }
$split = new QRsplit($string, $input, $modeHint); $split = new QRsplit($string, $input, $modeHint);
if(!$casesensitive) if(!$casesensitive)
$split->toUpper(); $split->toUpper();
return $split->splitString(); return $split->splitString();
} }
} }

View File

@ -1,172 +1,185 @@
<?php <?php
/* /*
* PHP QR Code encoder * PHP QR Code encoder
* *
* Toolset, handy and debug utilites. * Toolset, handy and debug utilites.
* *
* PHP QR Code is distributed under LGPL 3 * PHP QR Code is distributed under LGPL 3
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm> * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 3 of the License, or any later version. * version 3 of the License, or any later version.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
class QRtools { class QRtools {
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public static function binarize($frame) public static function binarize($frame)
{ {
$len = count($frame); $len = count($frame);
foreach ($frame as &$frameLine) { foreach ($frame as &$frameLine) {
for($i=0; $i<$len; $i++) { for($i=0; $i<$len; $i++) {
$frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
} }
} }
return $frame; return $frame;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037') public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037')
{ {
$barcode_array = array(); $barcode_array = array();
if (!is_array($mode)) if (!is_array($mode))
$mode = explode(',', $mode); $mode = explode(',', $mode);
$eccLevel = 'L'; $eccLevel = 'L';
if (count($mode) > 1) { if (count($mode) > 1) {
$eccLevel = $mode[1]; $eccLevel = $mode[1];
} }
$qrTab = QRcode::text($code, false, $eccLevel); $qrTab = QRcode::text($code, false, $eccLevel);
$size = count($qrTab); $size = count($qrTab);
$barcode_array['num_rows'] = $size; $barcode_array['num_rows'] = $size;
$barcode_array['num_cols'] = $size; $barcode_array['num_cols'] = $size;
$barcode_array['bcode'] = array(); $barcode_array['bcode'] = array();
foreach ($qrTab as $line) { foreach ($qrTab as $line) {
$arrAdd = array(); $arrAdd = array();
foreach(str_split($line) as $char) foreach(str_split($line) as $char)
$arrAdd[] = ($char=='1')?1:0; $arrAdd[] = ($char=='1')?1:0;
$barcode_array['bcode'][] = $arrAdd; $barcode_array['bcode'][] = $arrAdd;
} }
return $barcode_array; return $barcode_array;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public static function clearCache() public static function clearCache()
{ {
self::$frames = array(); self::$frames = array();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public static function buildCache() public static function buildCache()
{ {
QRtools::markTime('before_build_cache'); QRtools::markTime('before_build_cache');
$mask = new QRmask(); $mask = new QRmask();
for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) { for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
$frame = QRspec::newFrame($a); $frame = QRspec::newFrame($a);
if (QR_IMAGE) { if (QR_IMAGE) {
$fileName = QR_CACHE_DIR.'frame_'.$a.'.png'; $fileName = QR_CACHE_DIR.'frame_'.$a.'.png';
QRimage::png(self::binarize($frame), $fileName, 1, 0); QRimage::png(self::binarize($frame), $fileName, 1, 0);
} }
$width = count($frame); $width = count($frame);
$bitMask = array_fill(0, $width, array_fill(0, $width, 0)); $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
for ($maskNo=0; $maskNo<8; $maskNo++) for ($maskNo=0; $maskNo<8; $maskNo++)
$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
} }
QRtools::markTime('after_build_cache'); QRtools::markTime('after_build_cache');
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public static function log($outfile, $err) public static function log($outfile, $err)
{ {
if (QR_LOG_DIR !== false) { if (QR_LOG_DIR !== false) {
if ($err != '') { if ($err != '') {
if ($outfile !== false) { if ($outfile !== false) {
file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
} else { } else {
file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); 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); $width = count($frame);
for($y=0;$y<$width;$y++) { for($y=0;$y<$width;$y++) {
for($x=0;$x<$width;$x++) { for($x=0;$x<$width;$x++) {
echo ord($frame[$y][$x]).','; echo ord($frame[$y][$x]).',';
} }
} }
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public static function markTime($markerId) public static function markTime($markerId)
{ {
list($usec, $sec) = explode(" ", microtime()); list($usec, $sec) = explode(" ", microtime());
$time = ((float)$usec + (float)$sec); $time = ((float)$usec + (float)$sec);
if (!isset($GLOBALS['qr_time_bench'])) if (!isset($GLOBALS['qr_time_bench']))
$GLOBALS['qr_time_bench'] = array(); $GLOBALS['qr_time_bench'] = array();
$GLOBALS['qr_time_bench'][$markerId] = $time; $GLOBALS['qr_time_bench'][$markerId] = $time;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
public static function timeBenchmark() public static function timeBenchmark()
{ {
self::markTime('finish'); self::markTime('finish');
$lastTime = 0; $lastTime = 0;
$startTime = 0; $startTime = 0;
$p = 0; $p = 0;
echo '<table cellpadding="3" cellspacing="1"> 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> <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead>
<tbody>'; <tbody>';
foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
if ($p > 0) { if ($p > 0) {
echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>'; echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>';
} else { } else {
$startTime = $thisTime; $startTime = $thisTime;
} }
$p++; $p++;
$lastTime = $thisTime; $lastTime = $thisTime;
} }
echo '</tbody><tfoot> 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> <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr>
</tfoot> </tfoot>
</table>'; </table>';
} }
} public static function save($content, $filename_path)
{
//########################################################################## try {
$handle = fopen($filename_path, "w");
QRtools::markTime('start'); fwrite($handle, $content);
fclose($handle);
return true;
} catch (Exception $e) {
echo 'Exception reçue : ', $e->getMessage(), "\n";
}
}
}
//##########################################################################
QRtools::markTime('start');

214
phpqrcode/qrvect.php Executable file
View File

@ -0,0 +1,214 @@
<?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_VECT', true);
class QRvect {
//----------------------------------------------------------------------
public static function eps($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false)
{
$vect = self::vectEPS($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color, $cmyk);
if ($filename === false) {
header("Content-Type: application/postscript");
header('Content-Disposition: filename="qrcode.eps"');
echo $vect;
} else {
if($saveandprint===TRUE){
QRtools::save($vect, $filename);
header("Content-Type: application/postscript");
header('Content-Disposition: filename="qrcode.eps"');
echo $vect;
}else{
QRtools::save($vect, $filename);
}
}
}
//----------------------------------------------------------------------
private static function vectEPS($frame, $pixelPerPoint = 4, $outerFrame = 4, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false)
{
$h = count($frame);
$w = strlen($frame[0]);
$imgW = $w + 2*$outerFrame;
$imgH = $h + 2*$outerFrame;
if ($cmyk)
{
// convert color value into decimal eps format
$c = round((($fore_color & 0xFF000000) >> 16) / 255, 5);
$m = round((($fore_color & 0x00FF0000) >> 16) / 255, 5);
$y = round((($fore_color & 0x0000FF00) >> 8) / 255, 5);
$k = round(($fore_color & 0x000000FF) / 255, 5);
$fore_color_string = $c.' '.$m.' '.$y.' '.$k.' setcmykcolor'."\n";
// convert color value into decimal eps format
$c = round((($back_color & 0xFF000000) >> 16) / 255, 5);
$m = round((($back_color & 0x00FF0000) >> 16) / 255, 5);
$y = round((($back_color & 0x0000FF00) >> 8) / 255, 5);
$k = round(($back_color & 0x000000FF) / 255, 5);
$back_color_string = $c.' '.$m.' '.$y.' '.$k.' setcmykcolor'."\n";
}
else
{
// convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
$r = round((($fore_color & 0xFF0000) >> 16) / 255, 5);
$b = round((($fore_color & 0x00FF00) >> 8) / 255, 5);
$g = round(($fore_color & 0x0000FF) / 255, 5);
$fore_color_string = $r.' '.$b.' '.$g.' setrgbcolor'."\n";
// convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
$r = round((($back_color & 0xFF0000) >> 16) / 255, 5);
$b = round((($back_color & 0x00FF00) >> 8) / 255, 5);
$g = round(($back_color & 0x0000FF) / 255, 5);
$back_color_string = $r.' '.$b.' '.$g.' setrgbcolor'."\n";
}
$output =
'%!PS-Adobe EPSF-3.0'."\n".
'%%Creator: PHPQrcodeLib'."\n".
'%%Title: QRcode'."\n".
'%%CreationDate: '.date('Y-m-d')."\n".
'%%DocumentData: Clean7Bit'."\n".
'%%LanguageLevel: 2'."\n".
'%%Pages: 1'."\n".
'%%BoundingBox: 0 0 '.$imgW * $pixelPerPoint.' '.$imgH * $pixelPerPoint."\n";
// set the scale
$output .= $pixelPerPoint.' '.$pixelPerPoint.' scale'."\n";
// position the center of the coordinate system
$output .= $outerFrame.' '.$outerFrame.' translate'."\n";
// redefine the 'rectfill' operator to shorten the syntax
$output .= '/F { rectfill } def'."\n";
// set the symbol color
$output .= $back_color_string;
$output .= '-'.$outerFrame.' -'.$outerFrame.' '.($w + 2*$outerFrame).' '.($h + 2*$outerFrame).' F'."\n";
// set the symbol color
$output .= $fore_color_string;
// Convert the matrix into pixels
for($i=0; $i<$h; $i++) {
for($j=0; $j<$w; $j++) {
if( $frame[$i][$j] == '1') {
$y = $h - 1 - $i;
$x = $j;
$output .= $x.' '.$y.' 1 1 F'."\n";
}
}
}
$output .='%%EOF';
return $output;
}
//----------------------------------------------------------------------
public static function svg($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color, $fore_color)
{
$vect = self::vectSVG($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color);
if ($filename === false) {
header("Content-Type: image/svg+xml");
//header('Content-Disposition: attachment, filename="qrcode.svg"');
echo $vect;
} else {
if($saveandprint===TRUE){
QRtools::save($vect, $filename);
header("Content-Type: image/svg+xml");
//header('Content-Disposition: filename="'.$filename.'"');
echo $vect;
}else{
QRtools::save($vect, $filename);
}
}
}
//----------------------------------------------------------------------
private static function vectSVG($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;
$output =
'<?xml version="1.0" encoding="utf-8"?>'."\n".
'<svg version="1.1" baseProfile="full" width="'.$imgW * $pixelPerPoint.'" height="'.$imgH * $pixelPerPoint.'" viewBox="0 0 '.$imgW * $pixelPerPoint.' '.$imgH * $pixelPerPoint.'"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events">'."\n".
'<desc></desc>'."\n";
$output =
'<?xml version="1.0" encoding="utf-8"?>'."\n".
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">'."\n".
'<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" xmlns:xlink="http://www.w3.org/1999/xlink" width="'.$imgW * $pixelPerPoint.'" height="'.$imgH * $pixelPerPoint.'" viewBox="0 0 '.$imgW * $pixelPerPoint.' '.$imgH * $pixelPerPoint.'">'."\n".
'<desc></desc>'."\n";
if(!empty($back_color)) {
$backgroundcolor = str_pad(dechex($back_color), 6, "0", STR_PAD_LEFT);
$output .= '<rect width="'.$imgW * $pixelPerPoint.'" height="'.$imgH * $pixelPerPoint.'" fill="#'.$backgroundcolor.'" cx="0" cy="0" />'."\n";
}
$output .=
'<defs>'."\n".
'<rect id="p" width="'.$pixelPerPoint.'" height="'.$pixelPerPoint.'" />'."\n".
'</defs>'."\n".
'<g fill="#'.str_pad(dechex($fore_color), 6, "0", STR_PAD_LEFT).'">'."\n";
// Convert the matrix into pixels
for($i=0; $i<$h; $i++) {
for($j=0; $j<$w; $j++) {
if( $frame[$i][$j] == '1') {
$y = ($i + $outerFrame) * $pixelPerPoint;
$x = ($j + $outerFrame) * $pixelPerPoint;
$output .= '<use x="'.$x.'" y="'.$y.'" xlink:href="#p" />'."\n";
}
}
}
$output .=
'</g>'."\n".
'</svg>';
return $output;
}
}

0
phpqrcode/temp/tempfolder Executable file
View File

View File

@ -43,7 +43,8 @@
$QR_BASEDIR.'qrsplit.php', $QR_BASEDIR.'qrsplit.php',
$QR_BASEDIR.'qrrscode.php', $QR_BASEDIR.'qrrscode.php',
$QR_BASEDIR.'qrmask.php', $QR_BASEDIR.'qrmask.php',
$QR_BASEDIR.'qrencode.php' $QR_BASEDIR.'qrencode.php',
$QR_BASEDIR.'qrvect.php'
); );
$headerFile = $QR_TOOLSDIR.'merged_header.php'; $headerFile = $QR_TOOLSDIR.'merged_header.php';

View File

@ -1,2 +1,2 @@
#!/bin/sh #!/bin/sh
php ./merge.php php ./merge.php

View File

@ -6,14 +6,15 @@
* This file contains MERGED version of PHP QR Code library. * This file contains MERGED version of PHP QR Code library.
* It was auto-generated from full version for your convenience. * It was auto-generated from full version for your convenience.
* *
* This merged version was configured to not requre any external files, * This merged version was configured to not require any external files,
* with disabled cache, error loging and weker but faster mask matching. * with disabled cache, error logging and weaker but faster mask matching.
* If you need tune it up please use non-merged version. * If you need tune it up please use non-merged version.
* *
* For full version, documentation, examples of use please visit: * For full version, documentation, examples of use please visit:
* *
* http://phpqrcode.sourceforge.net/ * http://phpqrcode.sourceforge.net/
* https://sourceforge.net/projects/phpqrcode/ * https://sourceforge.net/projects/phpqrcode/
* https://github.com/t0k4rt/phpqrcode
* *
* PHP QR Code is distributed under LGPL 3 * PHP QR Code is distributed under LGPL 3
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm> * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>

View File

@ -1,11 +1,13 @@
/*
Code publié sous licence Apache 2.0
https://code.antopie.org/miraty/qr
*/
@font-face { @font-face {
font-family: "ubuntu-dl"; font-family: "ubuntu-dl";
src: url('ubuntu-dl.ttf'); src: url('ubuntu-dl.ttf');
} }
#redondance, #marge, #texte, #taille { #redondance, #marge, #texte, #taille {
appearance: none;
border: 2px @bordure solid; border: 2px @bordure solid;
border-radius: 7px; border-radius: 7px;
font-size: 20px; font-size: 20px;
@ -138,11 +140,11 @@ h1, #logo {
html { html {
margin: 10px; margin: 10px;
width: 400px; width: 100%;
} }
#texte { #texte {
width: 400px; width: 90%;
} }
h1 { h1 {
@ -156,8 +158,8 @@ h1, #logo {
} }
::placeholder { ::placeholder {
color: @texte; color: fadeout(@texte, 50%);
opacity: 0.6; opacity: 1;
} }
/* Infobulle */ /* Infobulle */
@ -175,7 +177,7 @@ h1, #logo {
position: absolute; position: absolute;
transform: scale(0) rotate(-12deg); transform: scale(0) rotate(-12deg);
color: #FFFFFF; color: #FFFFFF;
background: rgba(0,0,0,.9); background: rgba(0,0,0,1);
padding: 15px; padding: 15px;
border-radius: 3px; border-radius: 3px;
box-shadow: 0 0 2px rgba(0,0,0,.5); box-shadow: 0 0 2px rgba(0,0,0,.5);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 287 B