QR code, short for Quick Response code, was initially created to improve on bar codes used in inventory management. Nowadays, QR codes are ubiquitous, on posters, billboards, web pages, etc. This post will illustrate how to generate and read QR codes using the Linux command line interface (CLI).
The programs you will need to generate and read QR codes are qrencode and zbarimg respectively. (If you want to work with a GUI tool, there is QtQR.) To install the 2 programs on Debian:
$ sudo apt install qrencode zbar-tools
Background
A QR code is a matrix of square dots (or 'modules' in QRspeak). QR codes have as many as 40 versions of increasing data capacity. Version 1's dimension is 21 × 21 modules, and each higher version adds 4 modules per side ending with version 40 with 177 × 177 modules.
The exact maximum data capacity of a version depends on several factors, including the type of characters stored, e.g., numeric vs alphanumeric, and the level of error correction desired. At Medium error correcting capability, version 1 can store up to 20 alphanumeric characters; version 40, 3,391.
Fortunately, as we'll see next, the qrencode utility specifies good defaults, and hides much of the gory details from you.
QR code generation
In its simplest form, qrencode takes the input string to be encoded and outputs the PNG graphic to a file. The following command encodes the URL for this website.
$ qrencode -o webURL.png 'https://linuxcommando.blogspot.com/'
You can specify different parameters to fine-tune the QR code. Use the -l parameter to change the error correction level from the default L for Lowest to M for Medium, Q for Quite High, or H for Highest. In addition, you can explicitly specify the version to use, the size of the module and the margin, etc. The following example generates a version two QR code for the same website at the Highest error correcting level.
$ qrencode -o webURL.png -l H -v 2 'https://linuxcommando.blogspot.com/'
Besides the URL, marketers typically encode information such as phone numbers and email addresses.
$ qrencode -o webPhone.png '(604)555-1234'
$ qrencode -o webEmail.png 'spanish3rdlanguage@gmail.com'
Many QR code scanners will automatically open the associated app upon scanning a QR code of a special format, e.g., a browser for URLs, email client for email addresses, and phone app for telephone numbers.
QR code scanning
The Linux program zbarimg decodes the QR code stored in a file. To invoke, simply provide the input filename which contains the QR code.
$ zbarimg webURL.png
QR-Code:https://linuxcommando.blogspot.com/
scanned 1 barcode symbols from 1 images in 0 seconds
If you specify the -d parameter, zbarimg will display the QR code in addition to the decoded information.
The default camera app of recent Android or iOS phones can also function as QR code scanner. To scan, run the camera app and point it towards the QR code.
1 comment:
Thank you for useful article
Post a Comment