setLabel() public method

Set QR Code label (text).
public setLabel ( integer | string $label ) : QrCode
$label integer | string Label to print under QR code
return QrCode
 /**
  * @Route("/{text}.{extension}", name="endroid_qrcode", requirements={"text"="[\w\W]+", "extension"="jpg|png|gif"})
  */
 public function generateAction(Request $request, $text, $extension)
 {
     $qrCode = new QrCode();
     $qrCode->setText($text);
     if ($request->get('size') !== null) {
         $qrCode->setSize($request->get('size'));
     }
     if ($request->get('padding') !== null) {
         $qrCode->setPadding($request->get('padding'));
     }
     if ($request->get('error_correction_level') !== null) {
         $qrCode->setErrorCorrection($request->get('error_correction_level'));
     }
     if ($request->get('foreground_color') !== null) {
         $qrCode->setForegroundColor($request->get('foreground_color'));
     }
     if ($request->get('background_color') !== null) {
         $qrCode->setBackgroundColor($request->get('background_color'));
     }
     if ($request->get('label') !== null) {
         $qrCode->setLabel($request->get('label'));
     }
     if ($request->get('labelFontSize') !== null) {
         $qrCode->setLabelFontSize($request->get('labelFontSize'));
     }
     $qrCode = $qrCode->get($extension);
     $mime_type = 'image/' . $extension;
     if ($extension == 'jpg') {
         $mime_type = 'image/jpeg';
     }
     return new Response($qrCode, 200, array('Content-Type' => $mime_type));
 }
Example #2
0
 /**
  * Creates a QR code.
  *
  * @param array $options
  *
  * @return QrCode
  */
 public function createQrCode(array $options = array())
 {
     $options = $this->optionsResolver->resolve($options);
     $qrCode = new QrCode();
     if (isset($options['text']) && !is_null($options['text'])) {
         $qrCode->setText($options['text']);
     }
     if (isset($options['size']) && !is_null($options['size'])) {
         $qrCode->setSize($options['size']);
     }
     if (isset($options['padding']) && !is_null($options['padding'])) {
         $qrCode->setPadding($options['padding']);
     }
     if (isset($options['extension']) && !is_null($options['extension'])) {
         $qrCode->setExtension($options['extension']);
     }
     if (isset($options['error_correction_level']) && !is_null($options['error_correction_level'])) {
         $qrCode->setErrorCorrection($options['error_correction_level']);
     }
     if (isset($options['foreground_color']) && !is_null($options['foreground_color'])) {
         $qrCode->setForegroundColor($options['foreground_color']);
     }
     if (isset($options['background_color']) && !is_null($options['background_color'])) {
         $qrCode->setBackgroundColor($options['background_color']);
     }
     if (isset($options['label']) && !is_null($options['label'])) {
         $qrCode->setLabel($options['label']);
     }
     if (isset($options['label_font_size']) && !is_null($options['label_font_size'])) {
         $qrCode->setLabelFontSize($options['label_font_size']);
     }
     if (isset($options['label_font_path']) && !is_null($options['label_font_path'])) {
         $qrCode->setLabelFontPath($options['label_font_path']);
     }
     return $qrCode;
 }
 /**
  * Creates the QR code data corresponding to the given message.
  *
  * @param $text
  * @param int    $size
  * @param int    $padding
  * @param string $extension
  * @param mixed  $errorCorrectionLevel
  * @param array  $foregroundColor
  * @param array  $backgroundColor
  * @param string $label
  * @param string $labelFontSize
  * @param string $labelFontPath
  *
  * @return string
  */
 public function qrcodeDataUriFunction($text, $size = null, $padding = null, $extension = null, $errorCorrectionLevel = null, array $foregroundColor = null, array $backgroundColor = null, $label = null, $labelFontSize = null, $labelFontPath = null)
 {
     if ($size === null && $this->container->hasParameter('endroid_qrcode.size')) {
         $size = $this->container->getParameter('endroid_qrcode.size');
     }
     if ($padding === null && $this->container->hasParameter('endroid_qrcode.padding')) {
         $padding = $this->container->getParameter('endroid_qrcode.padding');
     }
     if ($extension === null && $this->container->hasParameter('endroid_qrcode.extension')) {
         $extension = $this->container->getParameter('endroid_qrcode.extension');
     }
     if ($errorCorrectionLevel === null && $this->container->hasParameter('endroid_qrcode.error_correction_level')) {
         $errorCorrectionLevel = $this->container->getParameter('endroid_qrcode.error_correction_level');
     }
     if ($foregroundColor === null && $this->container->hasParameter('endroid_qrcode.foreground_color')) {
         $foregroundColor = $this->container->getParameter('endroid_qrcode.foreground_color');
     }
     if ($backgroundColor === null && $this->container->hasParameter('endroid_qrcode.background_color')) {
         $backgroundColor = $this->container->getParameter('endroid_qrcode.background_color');
     }
     if ($label === null && $this->container->hasParameter('endroid_qrcode.label')) {
         $label = $this->container->getParameter('endroid_qrcode.label');
     }
     if ($labelFontSize === null && $this->container->hasParameter('endroid_qrcode.label_font_size')) {
         $labelFontSize = $this->container->getParameter('endroid_qrcode.label_font_size');
     }
     if ($labelFontPath === null && $this->container->hasParameter('endroid_qrcode.label_font_path')) {
         $labelFontPath = $this->container->getParameter('endroid_qrcode.label_font_path');
     }
     $qrCode = new QrCode();
     $qrCode->setText($text);
     if ($size !== null) {
         $qrCode->setSize($size);
     }
     if ($padding !== null) {
         $qrCode->setPadding($padding);
     }
     if ($extension !== null) {
         $qrCode->setExtension($extension);
     }
     if ($errorCorrectionLevel !== null) {
         $qrCode->setErrorCorrection($errorCorrectionLevel);
     }
     if ($foregroundColor !== null) {
         $qrCode->setForegroundColor($foregroundColor);
     }
     if ($backgroundColor !== null) {
         $qrCode->setBackgroundColor($backgroundColor);
     }
     if ($label != null) {
         $qrCode->setLabel($label);
     }
     if ($labelFontSize != null) {
         $qrCode->setLabelFontSize($labelFontSize);
     }
     if ($labelFontPath != null) {
         $qrCode->setLabelFontPath($labelFontPath);
     }
     return $qrCode->getDataUri();
 }