public static function downloadQrCode($url, $alias, $size = 300) { $urlDecoded = base64_decode($url); if ($size > 300) { $errorCorrection = 'high'; } elseif ($size > 100) { $errorCorrection = 'medium'; } else { $errorCorrection = 'low'; } if (empty($alias)) { $alias = $urlDecoded; $slashPos = strrpos($urlDecoded, '.de/'); if ($slashPos !== false) { $alias = substr($urlDecoded, $slashPos + strlen('.de/')); } else { $slashPos = strrpos($urlDecoded, '/'); if ($slashPos !== false) { $alias = substr($urlDecoded, $slashPos + 1); } } } $qrCode = new Endroid\QrCode\QrCode(); $qrCode->setText($urlDecoded)->setSize($size)->setPadding(10)->setErrorCorrection($errorCorrection)->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0))->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0)); $image = $qrCode->get(); $filename = preg_replace('#[^A-Za-z0-9._-]#', '', $alias) . '_' . $size . '.png'; header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . $filename); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . strlen($image)); print $image; exit; }
$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); echo $qrData; exit; /** * normalizeColor