Saturday, January 24, 2009

Google Charts QR-Code API

Google charts dynamically generates various kinds of charts as you need them--right in your browser or on a web page. Venn diagrams, bar graphs, pie graphs, and even maps are available! An interesting one is the dynamic generation of QR codes. A very appealing feature is that you can set the EC (error correction) level on these. I didn't see this in other online QR code generators. EC level H allows your code to be readable even if 30% of your code is obscured. That should be ideal for the purpose of embedding it in a manipulated image. It compares to the default level L, which only allows 7% of the data to be restored. Version number is set automatically depending on your request. I'm a little drunk now, so I may not be able to summarize it very well. Al Khahol can make you geeky (cuz it definitely don't make you sexy (unless the opposing party is even more drunk)).
Basically, you start with
http://chart.apis.google.com/
and add the chart type (cht)
chart?cht=qr
to indicate you are making a QR chart. Then you can add the other specifications or parameters, such as size. You can't get much smaller than 40 for a QR code, and I'm not sure what the upper limit is… (177x177 -- but you could be using multiple pixels per bit). Suppose it's 200x200.
&chs=200x200
That (chart size, chs) is obligatory. The output encoding default is UTF8 so you don't really need to add that. You could encode you Japanese kanji using Shift_JIS
&choe=Shift_JIS
otherwise you can leave it out. ISO-8859-1 is also available, whatever the hell that is.
Specify the L, lingual string(?) with
&chl=your text string here
Then my favorite part ,
chld=<L, M, Q, or H>|
This is the EC and margin, where you can specify error correction and margins, according to Google,

Four levels of error correction (EC) are available. The default level (L) allows the QR code to be read even if up to 7% of the code is misread, missing, or obscured. Other levels provide error correction for codes where up to 30% of the code cannot be read. The number of characters that can be encoded decreases as the EC level increases. See Versions, error correction and maximum characters for details.

The default margin is 4 modules. This means that a blank space equivalent to four rows at the top and bottom and four columns on the left and right is placed around the QR code. This is the minimum required by QR readers.

Optionally, specify an EC level and margin with

chld=|
Where:
is one of the following:

L allows 7% of a QR code to be restored

M allows 15% of a QR code to be restored
Q allows 25% of a QR code to be restored
H allows 30% of a QR code to be restored
and
defines the margin (or blank space) around the QR code. The default image has a margin equivalent to 4 rows / columns of the chart.
examples:

http://chart.apis.google.com/chart?cht=qr&&chs=240x240&chl=http://www.blues-tea-cha.blogspot.com/&chld=L|2
looks like

while
http://chart.apis.google.com/chart?cht=qr&&chs=240x240&chl=http://www.blues-tea-cha.blogspot.com/&chld=H|2
looks like

http://chart.apis.google.com/chart?cht=qr&chs=50x50&chl=http%3A%2F%2Fwww.blues-tea-cha.blogspot.com&chld=%3CH%3E|%3C2%3E
Some characters will change in the browser URL to appear as follows:
http://chart.apis.google.com/chart?cht=qr&&chs=50x50&choe=UTF-8&chl=http://www.blues-tea-cha.blogspot.com/&chld=%3CH%3E|%3C2%3E

so don't be confused.

If you type
http://chart.apis.google.com/chart?cht=p3&chd=t:90,1
0&chs=440x220&chl=Pacman|ghost
you get


Even more interesting is maps. For example, type (or cut and paste) http://chart.apis.google.com/chart?cht=t&chs=400x200&chd=s:_&chtm=world into your browser (or insert on your web site) and this map will appear.


440x220 seems to be the maximum size.
http://chart.apis.google.com/chart?cht=t&chs=440x220&chd=s:_&chtm=usa

No comments: