Generate your own QR code

Tuesday November 29, 2011 ()

In this blog we will demonstrate how to create your own QR (Quick Response) code and scan the code with your camera equipped Android phone/device. We will use Google Chart API to generate the actual code.

QR codes in the Google Chart API is just another type of chart. It uses the same root URL as the other charts. If you need to familiarize yourself with Google Chart API see this blog.

The table below shows the required request parameters to the Chart API for QR codes. This is taken directly from Google Chart documentation. See the Google Chart site to see the full request parameters.


Parameter Required or optional Description
cht=qr Required Chart type, specifies a QR code.
chs=<width>x<height> Required Image size
chl=<data> Required The data to encode. 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. Note that URLs have a 2K maximum length, so if you want to encode more than 2K bytes (minus the other URL characters), you will have to send your data using POST.

Here is the root URL for Google Chart API.

https://chart.googleapis.com/chart?

The Code

Suppose you want to create a QR code with a size of 200x200 pixels and data is https://kahimyang.com. The URL for your QR graphic should look like below:

https://chart.googleapis.com/chart?cht=qr&
chs=200x200&chl=https://kahimyang.com

Test your QR code

There is a Google project called Zebra Crossing or zxing. It includes a ready to use barcode scanner for Android. If you have an Android you may want to download this scanner and install it into your device.

Just point the camera of your phone to the QR code to scan.

That's it. Good luck.


2,359

Comments (Generate your own QR code)