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
-
The GNU Project Celebrates Its 40th Birthday
September 27 marks the 40th anniversary of the GNU Project, and it was celebrated with a hacker meeting in Biel/Bienne, Switzerland.
-
Linux Kernel Reducing Long-Term Support
LTS support for the Linux kernel is about to undergo some serious changes that will have a considerable impact on the future.
-
Fedora 39 Beta Now Available for Testing
For fans and users of Fedora Linux, the first beta of release 39 is now available, which is a minor upgrade but does include GNOME 45.
-
Fedora Linux 40 to Drop X11 for KDE Plasma
When Fedora 40 arrives in 2024, there will be a few big changes coming, especially for the KDE Plasma option.
-
Real-Time Ubuntu Available in AWS Marketplace
Anyone looking for a Linux distribution for real-time processing could do a whole lot worse than Real-Time Ubuntu.
-
KSMBD Finally Reaches a Stable State
For those who've been looking forward to the first release of KSMBD, after two years it's no longer considered experimental.
-
Nitrux 3.0.0 Has Been Released
The latest version of Nitrux brings plenty of innovation and fresh apps to the table.
-
Linux From Scratch 12.0 Now Available
If you're looking to roll your own Linux distribution, the latest version of Linux From Scratch is now available with plenty of updates.
-
Linux Kernel 6.5 Has Been Released
The newest Linux kernel, version 6.5, now includes initial support for two very exciting features.
-
UbuntuDDE 23.04 Now Available
A new version of the UbuntuDDE remix has finally arrived with all the updates from the Deepin desktop and everything that comes with the Ubuntu 23.04 base.