PHP


Generate QR code in PHP using google API

Generate QR code in PHP

The QR code (Quick Response Code) is the trademark for a type of matrix barcode. So, Let’s start to generate QR code in PHP. A QR code is a machine-readable code consisting of an array of black and white squares.

Normally we can say that QR code is the way to store the information in an image format. QR code first designed in 1994 for the automotive industry in Japan. These image information for reading from the camera on a smartphone.

What is QR Code

QR code contains a large amount of information in a single image, but people can not read in this image. This information only can be readable by the machine. In this tutorial, we’ll discuss the Google Chart API. This Google API helps to create a QR code easily. We can use this Google Chart API:

Generate QR code in PHP
Generate QR code in PHP

Call above Google API using cURL method in PHP. cURL is a library that lets you make HTTP requests in PHP. In the post filed some parameter are required by the API. Parameter cht=qr is Required for Specifies a QR code, Parameter chs=<width>x<height> is Required for Image size, and Parameter chl=<data> is Required for the data to encode.

cURL Initialization

Data can be digits (0-9), alphanumeric characters, binary bytes of data, or Kanji. You cannot mix data types within a QR code. The data must be UTF-8 URL-encoded.

Required Class

Create a class file for creating the QR code image in png format, this class contain the multiple methods to create your QR code image. After using this QR code class, simply call the relevant method and pass the information which is required by the method and then create your QR image:

Include this class file in your project file and create an object to make your QR code image:

Generate QR code in PHP

Now create your project file to use this class. Let’s take an example with this file fo generate QR code in PHP:

Conclusion

Finally, here is the output of the entire process and the QR code generated.

Generate QR code in PHP

Published by Amit Pandey

Professional Android app Developer, Full Stack Web Developer, Blogger, Entrepreneur And Founder of Coding Issue. I am always trying to learn new things or new possible ways to do things.

Did you find this page helpful?

X

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

*