A Linux Guide to Quick Response Codes and vCards

Yesterday, I reviewed a cool thing that I found years ago: Quick Response Codes, or QR Codes. I was going to attend an event where I might “work the room” and wanted an updated QR Code for my phone. So I spent part of my morning creating the file that I needed for the task. I was so enthused about my experience that I’m writing this article for you, today.

QR Codes are easy to use and they’re pretty much everywhere now. The purpose of a QR Code is to encode information in a barcode that can be easily scanned with a phone for reference. This is a little story about how I found out about QR Codes and how I create them and use them.

I can recall it so clearly now. I was standing outside a theater one day so many years ago. I had noticed that a movie poster had a QRCode on it. So I whipped out my phone, and found that I didn’t have a barcode reader, so I found one and installed it. The one I’ve been using for years since that day is a free and open source project called zxing for Android and it works great.

Anyway, there I was, in front of the theater, looking at this barcode. So I used my phone to scan the barcode and that led me to the website for the movie that the movie poster was promoting.

Later, I went home and looked up QR Codes. I found that the company that invented them received a patent for their invention and then the inventor donated the patent to the public domain. That was cool. And I thought, if they donated the patent, then there must be an open source project for creating QR Codes. Sure enough there was: qrencode.

Qrencode is a command line utility for Linux. If you run Ubuntu, Linux Mint (both Debian), or Red Hat Fedora Linux distributions, you will find that qrencode is available in the repositories for those distributions (and perhaps many more).

The examples I give here today will pertain to Ubuntu, which is what I use for my desktop computers. With some research, you will find analogous commands for the Linux distribution you use.

To install qrencode on Ubuntu:

sudo apt-install qrencode

You will be prompted for your user account password before installation begins. Enter it here.

Then you might want to check out the manpage for qrencode:

man qrencode

This will help you to learn the syntax for qrencode.

To make a QR Code with qrencode proceed as follows (adapted from the man page):

qrencode -o output.png 'Hello, world!'

The syntax is to invoke the command, specify a file name for output, and specify input with quoted text as shown above. There are numerous command line options available for qrencode, but for this article, I’m keeping it simple. Here is the output file for the command shown above:

Image for post
Image for post

Once I figured how to make a simple QR Code, I began to wonder what else I could do with it. One idea that I hit upon was a business card. Wouldn’t it be nice to have a business card that I could use in a barcode? You know, like a vCard?

So I proceeded to research the idea. There is a standard format for vCards which you can find here. I used that standard to format a text file that I can use for input for the qrencode command:

BEGIN:VCARD 
VERSION:2.1
N:Scott C. Dunn
ORG:Me
TITLE:Writer
TEL;MOBILE;VOICE:123-456-7890
ADR:123 No Name Street Salt Lake City, Utah 84119 EMAIL:scott@scottcdunn.com
URL:https://steemit.com/@digitalfirehose URL:https://medium.com/@scottcdunn URL:https://thedigitalfirehose.blogspot.com/
END:VCARD

For obvious reasons, I didn’t use a real address or phone number in the example above, but you can find my articles at the URLs shown above and the email address is real. If you write to me, I’ll respond.

While the tags for the vCard are not arbitrary, the text that follows is. You can put pretty much put anything you want on a vCard — as long as it is text. You will find the vCard 2.1 standard here.

Notice also, that I’m able to use multiple entries for URLs and that I can specify more than one phone number if I want to. The vCard format is flexible and easy to use. Here is the output file from that card:

Image for post
Image for post

And here is the command I used:

qrencode -o qrencode_sample_card.png < qrencode_sample_card.vcf

Qrencode in normal use is to specify text in quotes following the output file. It was a trick to figure out how to use a file as input for the command. The ‘<’ symbol is used to redirect output in Linux. We simply follow the input file name with the less than symbol to use a file as input for the command. Tutorials for qrencode abound on the internet and are easily found with your search engine of choice.

I also found over the years that there are many websites just for creating vCards and QR Codes. Yes, you could use them if you wanted to, and I considered using them myself. But I really liked learning about how it is done with a text file for the vCard and a program that I can install myself to create the image. Even today, I happened upon a way to use a cell phone to generate a vCard file from my phone. But I experienced a certain sense of satisfaction in learning the vCard format and writing the file to my liking with far more control than a purpose built website would provide.

Now instead of using a paper business card, I display my vCard on my phone as a QR Code. To make it easy to display the card, I uploaded the file to Google Drive, then created a shortcut on the home screen of my phone to open it.

I hope you enjoyed this tutorial and that you have found it to be useful.

Write on.

Originally published at steemit.com on September 23, 2018.

Written by

Husband, father, worker, philosopher, and observer. Plumbing the depths of consciousness to find the spring of happiness. Write on.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store