How to generate a QR code using Symfony, symfony generate _ PHP Tutorial

Source: Internet
Author: User
Symfony generates the QR code. Symfony is used to generate a QR code. this example describes how symfony generates a QR code. For your reference, I have found many ways to generate QR codes using Symfony on the Internet.

This example describes how to generate a QR code using Symfony. We will share this with you for your reference. The details are as follows:

There are many examples of using PHP to generate a QR code on the Internet:

First: Open APIs for google, As follows:

$urlToEncode="http://blog.it985.com";generateQRfromGoogle($urlToEncode);function generateQRfromGoogle($chl, $widhtHeight = '150', $EC_level = 'L', $margin = '0'){  $url = urlencode($url);  echo '';}

Appendix: API interface address https://developers.google.com/chart/infographics/docs/qr_codes

Type 2: Use the PHP class library PHP QR CODE

Official Address: http://phpqrcode.sourceforge.net/

: Http://sourceforge.net/projects/phpqrcode/

You can also click here to download.

Usage:

<? Php // include one of the two files:/* qrlib. php for full version (also you have to provide all library filesform package plus cache dir) OR phpqrcode. php for merged version (only one file, but slower and less accurate code because disabled cacheand quicker masking configured) * // two sentences: // contains qrlib. php needs to be put together with other files: files and folders. // Phpqrcode. php is a merged version. you only need to include this file, but the generated image is slow and inaccurate. include ('. /phpqrcode. php '); // the following two usage methods are provided: // Create a QR code file QRcode: png ('code data text', 'filename.png '); // creates file // generate an image to the browser QRcode: png ('Some othertext 1234 ');?>

See the official sample code for http://phpqrcode.sourceforge.net/examples/index.php.

Of course, there are other ways to generate a QR code, which will not be described here.

The following describes how to use EndroidQrCodeBundle to generate a QR code under Symfony:

1. use composer for installation
The code is as follows: composer require endroid/qrcode-bundle
2. Register in kernel

<?php// app/AppKernel.phppublic function registerBundles(){  $bundles = array(    // ...    new Endroid\Bundle\QrCodeBundle\EndroidQrCodeBundle(),  );}

3. define access routes

EndroidQrCodeBundle:  resource:  "@EndroidQrCodeBundle/Controller/"  type:    annotation  prefix:   /qrcode

4. configure config. xml

endroid_qr_code:  size: 100  padding: 10  extension: gif  error_correction_level: high  foreground_color: { r: 0, g: 0, b: 0, a: 0 }  background_color: { r: 255, g: 255, b: 255, a: 0 }  #label: "My label"  #labelFontSize: 16

5. Use in twig

Common text generation method:

 

Link generation method:
The code is as follows:
Permanent Address: http://blog.it985.com/12340.html
This article is from the IT985 blog. please indicate the source and relevant links when reprinting.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.