Creating and reading QR codes
Simplified
![](/var/linux_magazin/storage/images/linux-magazine.com/issues/2013/145/qr-code-generators/78002279_20.png/584073-1-eng-US/78002279_20.png_medium.png)
With the right tools, you can create your own QR code squares with information you want to share, for example, on a business card, in a letter, or on your website.
Read errors of unreliable, one-dimensional bar codes often caused interruptions in industrial production, prompting companies like Toyota and its subsidiary Denso Wave to develop as early as 1994 a new code for acquiring stock data. The new matrix bar code was designed to store more information than the traditional bar code and to stay legible, even if the label was dirty, wrinkled, or partially destroyed.
The quick response code, or QR code, comprises a matrix of square dots instead of the usual lines. Measuring up to 177 by 177 dots, the QR code encodes up to 4,296 characters, compared with a bar code that encodes just 13.
Thanks to numerous free reader apps for smartphones, QR codes have gained in popularity in recent years. Posters, catalogs, magazines, business cards, and even television screens display the small squares, offering additional information or URLs for microsites.
Data Grabber
If you want to encode your address into a QR code for a business card, you could try one of the many services on the Internet. However, restrictions typically apply. For example, some services allow only QR codes in a certain size or in limited quantities. Also, you never know for sure, what the services do with your data. For example, some sites explicitly allow sharing and selling the data to third parties in their terms of use, more or less pre-programming an increase in junk mail in the future. Fortunately, several QR code tools can help you avoid these problems in Linux.
On My Mark!
The quickest way to create a QR code is with the Qrencode [1] command-line utility. Any major distribution can install Qrencode via the package manager. The following command then creates a QR code containing the text "Hello World!" (Figure 1):
![](/var/linux_magazin/storage/images/linux-magazine.com/issues/2013/145/qr-code-generators/figure-1/584076-1-eng-US/Figure-1_large.png)
$ qrencode -o qrcode.png 'Hello World!'
The generated QR code ends up in the qrcode.png
file. If the file already exists, it's overwritten without prompting. If you have at least version 3.3.0 (qrencode -V
), Qrencode can generate an EPS graphic,
$ qrencode -t EPS -o qrcode.eps 'Hello World!'
or ASCII output (Figure 2). In the QR code image, the software creates a white border the width of one dot. This facilitates the process of deciphering the code for programs or the smartphone later on. If desirable, you can increase or decrease the edge with the -m
parameter; in the following example the border width would be 10 code pixels:
$ qrencode -m 10 -o qrcode.png 'Hello World!'
If you are saving the QR code in PNG format, the -s
parameter specifies the height of a black QR code pixel. By default, Qrencode draws every black dot three by three pixels. The program creates a slightly smaller QR code with quite a wide margin with the following command:
$ qrencode -s 2 -m 10 -o qrcode.png 'Hello World!'
A white border appears around the QR code that is exactly 20 screen pixels wide (10 QR code dots in width, with each dot two pixels). If you are creating EPS images, the only parameter available is -m
; -s
moves the entire QR code out of the image in this case. To control the resolution of PNGs further, use the -d
parameter to define the dpi.
Tolerance
Besides the specified data, the QR code contains additional error correction information. If a portion of the image is damaged, it allows you to reconstruct the missing or illegible data. The more additional information the QR code contains, the more heavily damaged it can be without becoming useless.
Increasing the error tolerance increases the size of the image because you need more black dots (Figure 3). The QR code standard thus uses four levels of error correction: H
level allows you to read all data if 30 percent of the QR code is destroyed, Q
level if 25 percent is unreadable, and M
level if just 15 percent is unintelligible. At the lowest level, L
, only 7 percent of the data can be faulty. In Qrencode, the -l
parameter selects the error correction level. The possible values are pretty much what you would expect: L
, M
, Q
, and H
.
![](/var/linux_magazin/storage/images/linux-magazine.com/issues/2013/145/qr-code-generators/figure-3/584082-1-eng-US/Figure-3_large.png)
The level you choose depends on the proposed use. If you expect the QR code to be exposed to external influences (e.g., wind, weather, graffiti) or if you are planning to manipulate the image deliberately (see the "Intruders" box), you will want the highest level, H
. On a business card, the lowest level, L
, is sufficient. If in doubt, simply omit the -l
parameter. The program then uses level L
by default.
Intruders
QR codes are quite robust against destructive behavior, which allows you put a logo or image in the middle. If the "foreign body" is small enough, the code still works, and it looks pretty, too.
None of the generators available for Linux can add images like this, however, which only leaves you with the option of switching to a web service or editing the image in another application. In the latter case, you will want to create the QR code with error correction level H as a precaution and then check that it works with a smartphone.
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.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.