コード例 #1
0
 public function codeAction()
 {
     $url = "";
     if ($this->getParam("name")) {
         $url = $this->getRequest()->getScheme() . "://" . $this->getRequest()->getHttpHost() . "/qr~-~code/" . $this->getParam("name");
     } elseif ($this->getParam("documentId")) {
         $doc = Document::getById($this->getParam("documentId"));
         $url = $this->getRequest()->getScheme() . "://" . $this->getRequest()->getHttpHost() . $doc->getFullPath();
     } elseif ($this->getParam("url")) {
         $url = $this->getParam("url");
     }
     $code = new \Endroid\QrCode\QrCode();
     $code->setText($url);
     $code->setPadding(0);
     $code->setSize(500);
     $hexToRGBA = function ($hex) {
         list($r, $g, $b) = sscanf($hex, "#%02x%02x%02x");
         return ["r" => $r, "g" => $g, "b" => $b, "a" => 0];
     };
     if (strlen($this->getParam("foreColor", "")) == 7) {
         $code->setForegroundColor($hexToRGBA($this->getParam("foreColor")));
     }
     if (strlen($this->getParam("backgroundColor", "")) == 7) {
         $code->setBackgroundColor($hexToRGBA($this->getParam("backgroundColor")));
     }
     header("Content-Type: image/png");
     if ($this->getParam("download")) {
         $code->setSize(4000);
         header('Content-Disposition: attachment;filename="qrcode-' . $this->getParam("name", "preview") . '.png"', true);
     }
     $code->render();
     exit;
 }
コード例 #2
0
ファイル: qrrender.php プロジェクト: ming-hai/XoopsCore
    case 'Q':
        $ec = Endroid\QrCode\QrCode::LEVEL_QUARTILE;
        break;
    case 'M':
        $ec = Endroid\QrCode\QrCode::LEVEL_MEDIUM;
        break;
    case 'L':
    default:
        $ec = Endroid\QrCode\QrCode::LEVEL_LOW;
        break;
}
$qrCode->setErrorCorrection($ec);
$qrCode->setModuleSize((int) $configs['qrcode_mps'] - 1);
$qrCode->setPadding($configs['qrcode_margin'] * $qrCode->getModuleSize());
$qrCode->setBackgroundColor(normalizeColor($configs['qrcode_bgcolor']));
$qrCode->setForegroundColor(normalizeColor($configs['qrcode_fgcolor']));
//$qrCode->setText("Life is too short to be generating QR codes");
//$qrCode->setSize(300);
try {
    $qrData = $qrCode->get('png');
} catch (\Exception $e) {
    $xoopsPreload->triggerEvent('core.exception', $e);
    $qrData = '';
}
$mimetype = \Xoops\Core\MimeTypes::findType('png');
$expires = 60 * 60 * 24 * 15;
// seconds, minutes, hours, days
header("Cache-Control: public, max-age=" . $expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
//header('Last-Modified: ' . gmdate('D, d M Y H:i:s T', $mtime));
header('Content-type: ' . $mimetype);