Creating and reading QR codes

Variety

Qrencode lets you encode any text, including URLs. You only need to use single quotes if blanks and non-standard characters appear in the text:

$ qrencode -o lpm.png http://www.linuxpromagazine.com

All modern QR code readers recognize that this is a web address and will offer to open it in the browser.

Getting an QR-encoded address automatically to enter a smartphone owner's address book is more difficult. In this case, you need to enter your address and some additional, cryptic information:

$ qrencode -o address.png 'BEGIN:VCARD VERSION:4.0 FN: N:Schuermann;Tim;;; ADR:;;Putzbrunner Str. 71;Munich;;81739; END:VCARD'

Typing this is not exactly easy, so to make life easier, you might prefer a QR code generator with a graphical user interface, such as QtQR [2].

QtQR

As the name suggests, QtQR is based on Qt. The tool relies on Python and the python-qrtools library. You can simply install the program via the package manager on Ubuntu. For other distributions, you will find the source code and RPM and DEB packages on the project's download page [3].

The main window in QtQR is quite simple: Top left in the selection you can set what data you want to store in the QR code. For an address, choose Contact Information (PhoneBook). Depending on the type of information, QtQR displays appropriate fields (Figure 4).

Figure 4: QtQR can also decode QR codes. Here, the software is reading a QR code saved as a file with the information shown in the left panel of the window.

As you fill out the fields, the program creates the corresponding QR code on the right. You can resize the code at top right. Pixel Size lets you set the number of pixels per square dot the QR code uses, whereas Margin Size lets you specify the size of the margin. Error Correction lets you define the correction level. Once you have set all parameters, save the code as a PNG file by clicking the Save QRCode button.

Portable QR-Code Generator

If QtQR's capabilities do not meet your needs, you can try Portable QR-Code Generator [4]. It also encodes geographical coordinates and WiFi access data, which can be useful if you want to offer guests quick access to WiFi as a hotel or coffee shop operator, for example.

Because Portable QR-Code Generator is written in Java, you must first install a Java run-time environment via the package manager. On Ubuntu, launch the Software Center and find the OpenJDK Java 7 runtime; on openSUSE 12.3, the matching package goes by the name java-1_7_0-openjdk.

The ZIP archive of the portable QR code generator is available from the project's Downloads page (to download, click on the Herunterladen link under the .zip entry). Unzip the file on your hard drive, open a terminal window, change to the directory with the extracted files, and run the command:

$ java -jar QRCodeGen.jar

The main window appears, and a small preview window (Figure 5) shows you the QR code. In the main window, look at the top edge first. Depending on the data you want to store in the code, click on the appropriate tab; that is, to save a URL, open the URL tab, and for an address, use VCard v4.

Figure 5: Portable QR-Code Generator offers numerous functions but also uses plenty of space on the screen – scrollbars are not included.

In the selected tab, the program displays appropriate fields. For an address, you will see more tabs that group the information, but you only need to fill out the required fields. If you do not want to specify a phone number, simply ignore the Telephone tab. If the address is already in a vCard file, you can import it by clicking Read VCard.

Once you have entered the data to encode, click on Generate. The results appear in the preview window. Plain text (in the Text tab) and geographic coordinates (in the Geo URI tab) are exceptions; the preview shows the code during entry.

You can define the size of the QR codes, as well as the error correction level at the bottom left under QR Code options section. In contrast to the previously featured tools, the Portable QR code generator allows you to specify the dimensions for the final image.

If you set Requested size (pixel) to 400, the resulting QR code image is 400 screen pixels wide. However, if you want to specify the size of each dot in the code, set Mode to Module size, then in Module size (pixel) define the number of pixels to form a dot. Additionally, you can select a specific Character encoding (see the "Character Encoding" box).

Character Encoding

QR codes contain no information about the encoding method used. Therefore, programs or apps simply try to guess. If this does not work, non-standard characters like umlauts are illegible. Because current apps assume UTF-8 encoding by default, you probably want to use this setting in the Character encoding drop-down box in Portable QR-Code Generator.

To be on the safe side (e.g., because you have business partners in several countries), you should avoid non-standard characters and model your input on the ISO 8859-1 standard [5]. For more on the topic of character encoding, check out the Wikipedia entry on character encoding [6].

To the right, in the QR Code details panel, you will see some statistics that reveal, among other things, how many bytes of payload (Data byes) the QR code currently displayed contains. To check the text that the Portable QR code generator actually dumped into the QR code, look at the bottom of the window; the details are in the Data field.

You can copy the generated QR code to the clipboard (Edit | Copy QR Code to clipboard) or save a PNG format image file with File | Save As.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
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

News