protected function createQrCode(MediaInterface $media)
 {
     $path = tempnam(sys_get_temp_dir(), 'sonata_media_qrcode_reference') . '.' . $this->config['extension'];
     $qrCode = new QrCode();
     $qrCode->setText($media->getBinaryContent())->setSize($this->config['size'])->setPadding($this->config['padding'])->setErrorCorrection($this->config['error_correction'])->setForegroundColor($this->config['foreground'])->setBackgroundColor($this->config['background'])->setLabel($this->config['label'])->setLabelFontSize($this->config['label_size'])->setImageType($this->config['extension']);
     if ($this->config['logo'] && is_file($this->config['logo'])) {
         $qrCode->setLogo($this->config['logo']);
     }
     $qrCode->save($path);
     return $path;
 }
Example #2
0
 /**
  * Add qr code
  *
  * @param string $text
  * @param array $options
  * @return PrintContent
  * @throws \Endroid\QrCode\Exceptions\DataDoesntExistsException
  * @throws \Endroid\QrCode\Exceptions\ImageFunctionFailedException
  * @throws \Endroid\QrCode\Exceptions\ImageFunctionUnknownException
  */
 public function addQrCode($text, array $options = [])
 {
     $options = array_merge(['size' => null, 'padding' => null, 'logo' => null, 'logo_size' => null], $options);
     $qrCode = new QrCode();
     $qrCode->setText($text);
     if (is_numeric($options['size'])) {
         $qrCode->setSize($options['size']);
     }
     if (is_numeric($options['padding'])) {
         $qrCode->setPadding($options['padding']);
     }
     if ($options['logo'] && file_exists($options['logo'])) {
         $qrCode->setLogo($options['logo']);
         if (is_numeric($options['logo_size'])) {
             $qrCode->setLogoSize($options['logo_size']);
         }
     }
     return $this->addPhoto($qrCode->get('jpg'));
 }