How does Symfony generate a QR code _ php instance

Source: Internet
Author: User
This article describes how to generate a QR code using Symfony. The example shows how to use google open api and PHP class library phpqrcode, in addition, the detailed steps and implementation methods for using EndroidQrCodeBundle to generate a QR code under Symfony are described in the example below. For more information, see the example below. 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.