QRencode | Generate QR Codes in the Terminal

There are a lot of web based tools out there to create simple QR codes, but why use a website when you can use the terminal? Generating a QR code in the terminal is pretty easy to do and actually quite convenient. The syntax is easy to follow and therefore makes for an easy time to create all the QR Code goodness you could ever want.

This article will provide several examples of how to use qrencode to make QR codes and some additional options that may make your QR Codes work better for your use case. Below are some basic examples that can be done created with one line in the terminal to also using a text file as the input for the QR Code.

What is a QR Code?

A QR Code, or also known as a Quick Response Code is rather convenient method to encode information into a pixelized square that has three distinct boxes in three of the four corners in what seems like a sea of random pixels with smaller squares floating in the midst of it. I can assure you that it isn’t random, but you probably knew that already. Those three squares in the corner are used to define the orientation of the code for the scanning device.

QR Codes are an invention of the 1990s by a subsidiary of Toyota called Denso Wave. The purpose was to improve inventory tracking, assembly and basically any factory related task where some condition has to be documented.

You can now take that industrial designed capability and use it for any sort of communication you want to send to an end user with a smartphone. There are all sorts of applications for which I will outline what I think is most useful and some options there about.

It should also be noted that there are countless online QR Code generating services but I think that is lame if you can do it yourself locally. Even more excitingly, in the terminal where you can let your imagination run wild for the potential solutions this may provide in countless situations.

Installation

This is a terminal application so the installation instructions are all terminal here:

openSUSE

sudo zypper install qrencode

Fedora

sudo dnf install qrencode

Debian Based

sudo apt install qrencode

Use

I just needed simple numbers. Because the output is nothing more than a PNG file, and by nature, it is a series of pixels, it is easy to take the small file and scale it to the size you need on whatever medium you are putting it like a business card, document, sign, etc.

Basic

Here you can put a short message or just communicate a bit of text. This was actually my primary reason for looking into this. I needed to generate some numbers. This, super easy works fantastically well.

qrencode -o 8.png -t png "8"

This will create, in whatever directory you are working a simple png with the data.

I don’t NEED anything more complex but I thought, how much text can I put in this “simple message” of a QR Code

qrencode -o qbf.png -t png "Quick Brown Fox Jumps Over the Lazy Dog"

This created a larger QR Code which makes sense because there is more data in it.

Then I thought, can I pipe a text document into this as a way of encoding a paragraph of information. I took the first paragraph from this site’s homepage, put it in a text file. Just use the -r option and the file name or path to file.

qrencode -o homepage.png -r homepage.txt 

This spit out a rather large QR Code with the text all jammed up in there.

This sent me down quite the rabbit hole, more on that in a bit.

URL

Perhaps one of the easiest, and most common way of using QR codes is to get to a particular web page. I think this is a pretty cool usage but do be careful when out in public. It’s generally not a good idea to scan any QR Code unless you really pay attention to what is being done with that code. Regardless, here is a QR Code for navigating to CubicleNate.com

qrencode -o cubiclenate.png "https://cubiclenate.com"

This can also send you a link to a Telegram chat or Discord server, where ever on the web you want to send people.

Email

Much like a URL, you can have a QR Code be used to provide an email address with subject and the start of a body, if you so choose. Basically, the parts generally needed to actually SEND an email.

qrencode -o email.png "mailto:qrcode@cubiclenate.com?subject=QR Code Blathering&body=Wow, you took the time to blather about QR Codes... go you!"

There can be lots of uses here, of course. Email is still pretty dang cool, totally decentralized even if it is filled with a lot of annoyances.

SMS

Another handy thing you can do with a QR Code is to send an SMS or text message to a desired recipient. This is certainly pretty cool, but a practical use escapes me at this point.

qrencode -o "sms.png" "smsto:5555555555:This SMS was generated from a QR Code."

Contact with vCard

Another handy use for QR codes is to share contact information. It’s very easy to mistype some bits of ones contact information, especially when you have a lot of details. This is an easy way to share you contact info accurately. Using the vCard (VCF or Virtual Contact File) format, create a text file with the information which can be directed into the command. For example, create a contact file called contact.txt

In the same directory you created this, run the command:

qrencode -o contact.png -r contact.txt

The information above will create a nice little card like this that could be placed on a business card or distributed anyway you like.

Calendar Event

I think this would be great to use to share upcoming events. A quick way to get a group of people to put an event on their calendar. The easy way of making this happen is to create an event in a calendar application of your choice and emailing it to yourself to convert into the QR Code, but there is so much extra nonsense in those so here is what you NEED to make a successful event. You can use this format below and swap in your own details.

The only real tricky thing is the date portion of it. If you cannot already tell, it is in Zulu or GMT / UTC time.

YYYY – 4 digit year
MM – 2 digit month
DD – 2 digit day
T – Signifies the beginning of the time portion
HH – 2 digit hour
MM – 2 digit minute
SS – 2 digit second
Z – signifies that it is UTC time.

If you remove the Z, it will default to whatever local timezone is.

Further details can be found here on all the bits and pieces of the ical standard

https://icalendar.org/iCalendar-RFC-5545/3-6-1-event-component.html

Connect to a WiFi Network

There are a lot of uses for this. Lets say you are helping an organization with their IT systems and they have a guest network available for patrons or visitors. You want to offer WiFi and want to make it as convenient as possible. Here is how you do it.

Firstly, you need to know the details of the network, the type of security, the SSID and the password and cram them into a single line. Here the format:

qrencode -o "wifi.png" "WIFI:T:WPA;S:SSID;P:PSWD;;"

WIFI, followed by a colon : is the keyword the phone or device knows that the rest is for the network.

T: defines the type of security. Most security will be WPA or WPA2 but WEP is also an option. Close the section with a semi-colon. ;

S: Is the SSID or “Service Set ID” or the WiFi network name. This section is also closed with a semi-colon. ;

P: is the password / passpharase for the network. Also called a “security key”. This section is ended with two semi-colons. ;;

Here is an example of a fake network:

qrencode -o "wifi.png" "WIFI:T:WPA;S:Network;P:P@$$word123;;"

I do want to note that my Linux Desktop Environment, Plasma, will generate these automatically for you which is rather handy.

Additional Features

There are some additional features I have omitted from the lines of code I have shared. Mostly for simplicity and making the lines easier to read but I find these to be very important, depending on your use case.

Size of Blocks

-s NUMBER, –size=NUMBER

This specifies the size of each block in pixels. The default is 3, so if that is good enough for you, than keep it as such. I would recommend something a bit larger but also keep in mind that you can take these files and easily scale them up and should find to degradation in quality, after all, they are made up of large pixels.

As an example, I will use the Quick Brown Fox code and add the size option of 8 pixels:

qrencode -s 8 -o qbf.png -t png "Quick Brown Fox Jumps Over the Lazy Dog"

Level of Error Correction

-l {LMQH}, –level={LMQH}

Depending on the amount of data you are putting in the QR code and what the possibility is of the code experiencing damage, you can set the error correction level accordingly. There are four options. L, M, Q and H where (lowest) to H (highest). The default is L.

L – Low, allows the code to be successfully scanned if up to 7% of the code unreadable.

M – Medium, 15% of the code can be unreadable

Q – Quite High, 25% of the code can be unreadable

H – High, 30% of the code can be unreadable.

Same example as above but with a Quite high level of error correction.

qrencode -l Q -o qbf.png -t png "Quick Brown Fox Jumps Over the Lazy Dog"

For easy comparison, here is the Low level of error correction

8-Bit Encoding

-8, –8bit

This option caught my eye because it said “8-Bit” and that is always a winner, somehow, for me. This option encodes entire dataset in 8-bit mode where the options -k, -c and -i will be ignored. For context, K is kanji, C is case sensitive and I is to ignore case distinction and only use upper-case characters. Just for fun, Quick Brown Fox in glorious 8-bit encoding.

Final Thoughts

There are many other options for you to explore with qrencode. These happen to be the examples that I think are most useful and could have immediate benefit in various areas of your life. Whether it is providing quick and accurate contact or event information to logging into a WiFi network more easily. The SMS and Email options could be useful for certain types of way-finding games too, I suppose. There is much fun to be had here, for sure.

I’m grateful that the syntax for qrencode is easy to follow and as such, could also, very easily, be incorporated into other projects in that good ‘ol Unix philosophy of programming. Really, the sky is the… or rather, the size of the print out is your limit framed effectively with your imagination.

References

https://fukuchi.org/works/qrencode
https://en.wikipedia.org/wiki/VCard
https://icalendar.org/iCalendar-RFC-5545/3-6-1-event-component.html

2 thoughts on “QRencode | Generate QR Codes in the Terminal

  1. KDE Plasma allows to turn the clipboard content to a qrcode at a click of a button. I use this most times.

Leave a Reply