..


Sponsored Links

A class to create QR Codes using PHP

Article written by Ciro Cardone
Page 1 of 3

This article addresses a topic of great relevance: we will go in and see how the QR Codes crearceli alone through the Google Chart API and PHP.

What are QR Codes

QR codes are two-dimensional bar code of a rectangular designed to be read and decoded quickly, the feature to which they are named: Quick Response.

Being developed to be decoded quickly, QR Codes are primarily used to store information (such as the URL of a web page or an app, or a phone number) to be read by mobile devices (smartphones), which are generally equipped with software to allow for easy decoding.

Below we see a practical example of the use of QR codes, we have, in fact, inserted containing a link to the home page of centre-equestre-lepuy.com. Thus, if the article was printed, you can quickly access this website through any device dodato an interpreter of QR Codes.

QR code

Another important feature is the robustness of these codes. In fact, even if they are damaged (think, for example, spots on the printed page) with the code Reed-Solomon was able to recover up to 30% of the information contained in QR Code compromise.

We see in this table, four levels of error correction available for QR Codes and their resilience:

Level % Of recoverable data
L 7%
M 15%
Q 25%
H 30%

Storage Capacity

QR codes can store up to 7,089 numeric characters or up to 4,296 alphanumeric characters. Being square-shaped codes have an equal number of rows and columns, and just by their number depends on the storage capacity of QR Code
The number of rows and columns of a QR code is identified by its version. The versions range from 1 to 40, and the increase of a version involves the addition of 4 rows and 4 columns, you start to get 21 to 177. So a QR code of version 1 is a square made up of 21 rows and 21 columns with a storage capacity up to 25 alphanumeric characters, while a QR code of version 40 has 177 rows and 177 columns and maximum storage capacity.

Storage capacity for some version:

Version Rows x Columns Level error correction Maximum number of characters
Numerical Alphanumeric Binary Kanji
1 21x21 L 41 25 17 10
M 34 20 14 8
Q 27 16 11 7
H 17 10 7 4
2 25x25 L 77 47 32 20
M 63 38 26 16
Q 48 29 20 12
H 34 20 14 8
10 57x57 L 652 395 271 167
M 513 311 213 131
Q 364 221 151 93
H 288 174 119 74
40 177x177 L 7.089 4.296 2.953 1.817
M 5.596 3.391 2.331 1.435
Q 3.993 2.420 1.663 1.024
H 3.057 1.852 1.273 784

The storage capacity of a QR Code depends only on its version and the level of error correction (as the level is low, the greater the amount of data storage), not by its size in pixels.

QR Code with Google Chart API

The Google Chart API is an API made ​​available by Google that returns an image containing a graph in response to a request made ​​by GET or POST.
There are different types of graphs that can be created through this API, but we will concentrate solely on the charts of QR Code

The URL to which requests to do to get a chart is https://chart.googleapis.com/chart to which are added the necessary parameters, which in our case are:

  • cht: type of graph, in our case cht = qr
  • chs: Image size in format width x height
  • chl: The data included in our QR Code in the UTF-8
With these three parameters we are already able to create our own QR Code, but we wanted the option of using two optional parameters:
  • Choe: Encoding of the graph, the possible values ​​are: UTF-8 (Default), Shift_JIS, ISO-8859-1. It is recommended to leave UTF-8 except in the case of special needs.
  • CHLD: Level of error correction: The (default), M, Q, H
The version of the QR code is automatically determined by the API, which takes into account the number of characters and the selected level of error correction. Keep in mind however, that a smart phone, normally can only read up to the QR Code version 4.

An example of a request to generate a QR Code is https://chart.googleapis.com/chart?cht=qr>

In the same category ...
E-Learning
Linux (Course) Linux (Course)
Complete guide to open-source system. From 49 €.
MySQL (Course) MySQL (Course)
Management of open-source database. From 39 €.
PHP (Course) PHP (Course)
Full course for creating dynamic Web sites. From 49 €.
Sponsored Links