New file |
0,0 → 1,74 |
<?php |
/** |
* BarcodeQR - Code QR Barcode Image Generator (PNG) |
* |
* @package BarcodeQR |
* @category BarcodeQR |
* @name BarcodeQR |
* @version 1.0 |
* @author Shay Anderson 05.11 |
* @link http://www.shayanderson.com/php/php-qr-code-generator-class.htm |
* @license http://www.gnu.org/licenses/gpl.html GPL License |
* This is free software and is distributed WITHOUT ANY WARRANTY |
*/ |
final class QrCode { |
|
private $API_CHART_URL = ''; |
private $taille = '150'; |
private $contenu; |
private $urlQrCodeTpl; |
private $dossierQrCode; |
|
public function __construct($conteneur) { |
$this->API_CHART_URL = $conteneur->getParametre('urlApiChart'); |
$this->dossierQrCode = $conteneur->getParametre('dossierQrCode'); |
$this->urlQrCodeTpl = $conteneur->getParametre('urlQrCodeTpl'); |
} |
|
/** |
* URL code |
* |
* @param string $url |
*/ |
public function setUrl($url = '') { |
$this->contenu = $url; |
} |
|
/** |
* Taille du QRcode en pixel. Cela sera forcément un carré. |
* |
* @param string $taille |
*/ |
public function setTaille($taille) { |
$this->taille = $taille; |
} |
|
/** |
* Generate QR code image |
* |
* @param string $filename |
* @return bool |
*/ |
public function dessiner($idQrCode = null) { |
if (!preg_match('/\.png$/i', $idQrCode)) { |
$idQrCode .= '.png'; |
} |
$cheminImg = $this->dossierQrCode.$idQrCode; |
if (file_exists($cheminImg) == false) { |
$ch = curl_init(); |
curl_setopt($ch, CURLOPT_URL, $this->API_CHART_URL); |
curl_setopt($ch, CURLOPT_POST, true); |
curl_setopt($ch, CURLOPT_POSTFIELDS, "chs={$this->taille}x{$this->taille}&cht=qr&chl=".urlencode($this->contenu)); |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
curl_setopt($ch, CURLOPT_HEADER, false); |
curl_setopt($ch, CURLOPT_TIMEOUT, 30); |
$img = curl_exec($ch); |
curl_close($ch); |
|
file_put_contents($cheminImg, $img); |
} |
$urlQrCode = sprintf($this->urlQrCodeTpl, $idQrCode); |
return $urlQrCode; |
} |
} |
?> |