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(); // For Debugging //curl_setopt($ch, CURLOPT_VERBOSE, TRUE); //curl_setopt($ch, CURLOPT_STDERR, $f = fopen("$cheminImg.txt", "w+")); 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); // For Debugging //fclose($f); file_put_contents($cheminImg, $img); } $urlQrCode = sprintf($this->urlQrCodeTpl, $idQrCode); return $urlQrCode; } } ?>