Creating a simple QR code in Linux with qrencode
Hi everyone,
Today, I will show you how easy it is to create QR codes in Linux with a command-line tool called qrencode.
QR codes have risen in popularity since the COVID-19 pandemic started. It is used on some restaurants as a way to allow customers to see a menu on their phones, since most phones offers a QR code scanner built-in.
QR codes are also a good way to put some sort of links into documents, flyers, and more. For example: “For more information, scan this QR code”.
In Linux, we can easily create and save QR codes as a PNG image that you can then import into your documents, upload to your website, share in your posts, or place anywhere you can imagine. First, we do need to install this utility which is included in Ubuntu’s apt repo. The installation is very easy and we will see basically the only step below.
Installing qrencode
To install qrencode, open a terminal window and simply type sudo apt install qrencode
:
And that’s it. You now have qrencode installed. You should see that apt installed it correctly, like this:
Using qrencode
To use qrencode, you use the following command line:
qrencode -o {output.png} "{text to encode}"
- output.png is the filename to save the QR code. You can name it anything but specify the .png extension.
- “Text to encode” is self-explained. You place here the text you want to encode to a QR code. It can be a text or link.
Here is an example:
And here is the QR file saved:
We named the file website_qr.png
, and we can see it saved above.
Displaying a QR code in the screen using stdin and imagemagick’s display
We can also show a temporary QR code in the screen very easy. And example of why youĺl want to do this is to send and open URLs to your phone, especially if you have your browser’s sync settings turned off.
To do this, we use imagemagick’s display
tool. First, we must be sure to have imagemagick installed in our machine. We can do it with apt by typing sudo apt install imagemagick
.
Now that we installed or confirmed that imagemagick is installed, we can create a QR code to show on the screen really simple with the following command line:
qrencode -o - "{Text to encode}" | display
Here, instead of specifying a filename, we use -
to indicate that the output should be written to the stdin. We then pipe with | and use the display
tool to show what qrencode wrote to the stdin.
It should then open a small window showing the QR code:
And that’s it! We have now successfully generated a QR code using the qrencode
utility.