Creating and reading QR codes
KDE Applications
KDE users have an easy way to convert text into QR code: Copy some text to the clipboard, click the Klipper tool (the scissors) in the system section of the control bar at the bottom, and select Show Barcode. Unfortunately, the interface does not let you save the QR code shown on the left side (Figure 6) or copy it to the clipboard. Your only workaround is to grab a screenshot with KSnapshot. For a single QR code this will still be faster than installing one of the other tools.
A possible alternative is the slightly older KBarcode4-light. To use it, first install PyQt via the package manager. On openSUSE 12.3 and Ubuntu, it resides in the python-qt4
package. Next, unpack the KBarcode4-light archive, which you downloaded off the web [7]. In the src
subdirectory, run the python kbarcode.py
command.
In the window that now appears (Figure 7), select the QR Code item in the Encoding drop-down, then type the text to encode in Value, and press Generate. The resulting QR code appears at the bottom. Pressing Save as PDF lets you save the code in a text file.
Theoretically, it's possible to export the QR code as an image file, but clicking Save on modern distributions only leads to an error message in the terminal. Another alternative is to click Copy and then paste the Clipboard contents into another program. The options offered in the Basic Options and Extra Options tabs are useless for QR codes.
Bookworms
Although dozens of apps are out there for reading QR codes with smartphones, only a few fairly rudimentary programs exist for Linux. If you have QtQR installed, press Decode in the bottom right corner of the main window. The program either accepts the QR code as an image file (Decode from File), or reads it via a webcam (Decode from Webcam).
However, QtQR is quite picky: For example, it does not interpret QR codes for dots of exactly one pixel. Additionally, the program stubbornly insists that the text contains ISO-8859-1 character encoding. If you have a QR code image file, one option is to use the Libdecodeqr-simpletest program, which is actually only intended as an example program for programmers on how to read codes in their own programs with the Libdecodeqr library. However, it is excellent for reading codes at the command line.
On Ubuntu, you can install the reader from the libdecodeqr-examples package with:
sudo apt-get install libdecodeqr-examples
Owners of other distros first need to install a C++ compiler, make, and developer files from OpenCV (on openSUSE, in the opencv-devel package). Then, use the archive of the current version [8] from the Latest Stable Source Code section. Extract it on your hard drive, and in the resulting src
subdirectory, enter the following three commands: ./configure
, make
and sudo make install
.
As soon as the program exists on your hard drive, you can decipher QR code in the qrcode.png
file with the following command:
$ libdecodeqr-simpletest qrcode.png
… at least in theory; the practical results will be disappointing in many cases. In my tests, libdecodeqr-simpletest
simply refused to see any data in the QR codes (Figure 8).
Touch the Bar!
A much better alternative is ZBar [9]. This program reads QR codes from files or via a connected webcam. Ubuntu includes the small tool in the zbar-tools package. On other distributions, you first need to run the package manager to install the developer packages for Qt4, PyGTK and ImageMagick. On openSUSE 12.3, they are named libqt4-devel, python-gtk-devel, and ImageMagick-devel.
If you want to read the QR code with the webcam, you additionally need the kernel header files; on openSUSE 12.3, they are located in the kernel-devel package. If you want to do without this function, you must use the --disable-video
configuration parameter to disable it explicitly. After unpacking the source code, you can install the software with ./configure && make && sudo make install
. To decode a PNG file with a QR code in ZBar, use:
zbarimg -d <file>.png
The -d
parameter ensures that a window with the QR code appears (Figure 9) in addition to the decoded information in the terminal window. If you want to read a QR code with a camera, you need to launch zbarcam
. This pops up a preview window with the image from the webcam. Now hold up the QR code to the camera. Once the program has detected the code, it draws a green border around the QR code and prints the data in the terminal window (see the Big and Colorful" box).
Big and Colorful
Whether a webcam or smartphone can recognize a QR code depends on the quality of the built-in camera. To make sure even models with bad sensors can detect all the dots, you should not print the code too small. Generally, the image should be not less than 2.5 by 2.5 centimeters. To achieve this, simply enlarge the generated QR code with an image editing program, but make sure the software does not modify image sharpness. In GIMP, choose Image | Scale image, and then in the new window, say No to Interpolation.
Most QR codes are black and white to achieve the best possible contrast, but in principle, nothing is wrong with coloring the pixels, although you run the risk that some smartphones would not be able to distinguish individual pixels. Testing sample code with two or more different, older smartphones would give you a clue as to the quality of the results.
You can disable the preview with the --nodisplay
switch; raw
delivers the raw data, and xml
packages the data in an XML format. The above three parameters help if you want to integrate the tool into a script. The parameters --raw
and --xml
can also be used with zbarimg
.
« Previous 1 2 3 4 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs