Exemplo n.º 1
0
 /**
  * Renders a img tag with a base64-encoded QR code
  * @param string $message
  * @param string|null $extension
  * @param int|null $size
  * @param null $padding
  * @param array $attribs
  * @return mixed
  */
 public function renderBase64Img($message, $extension = null, $size = null, $padding = null, $attribs = array())
 {
     if (isset($extension)) {
         if (is_array($extension)) {
             $attribs = $extension;
             $extension = null;
         } elseif (isset($size)) {
             if (is_array($size)) {
                 $attribs = $size;
                 $size = null;
             } elseif (isset($padding) && is_array($padding)) {
                 $attribs = $padding;
                 $padding = null;
             }
         }
     }
     $image = $this->qrCodeService->getQrCodeContent($message, $extension, $size, $padding);
     $contentType = $this->qrCodeService->generateContentType(isset($extension) ? $extension : QrCodeServiceInterface::DEFAULT_EXTENSION);
     return $this->renderer->render(self::IMG_BASE64_TEMPLATE, array('base64' => base64_encode($image), 'contentType' => $contentType, 'attribs' => $attribs));
 }
Exemplo n.º 2
0
 /**
  * Generates the QR code and returns it as stream
  */
 public function generateAction()
 {
     $extension = $this->params()->fromRoute('extension', QrCodeServiceInterface::DEFAULT_EXTENSION);
     $content = $this->qrCodeService->getQrCodeContent($this->params());
     return $this->createResponse($content, $this->qrCodeService->generateContentType($extension));
 }