Creating and reading QR codes in Linux through cli

Sumit Dhattarwal
2 min readJul 16, 2023

--

Introduction:

QR codes have gained immense popularity as a convenient way to store and share information. In this tutorial, we will explore how to create QR codes from text using the Linux terminal and decode the content of QR code images. By leveraging command-line tools like ‘qrencode’ and ‘zbarimg’, you can easily generate and read QR codes right from your terminal. Let’s dive in and learn how!

Part 1: Creating a QR Code from Text

Step 1: Install qrencode

Make sure you have the qrencode tool installed on your Linux system. Open the terminal and execute the following command:

dnf install qrencode

Step 2: Generate the QR code: With qrencode installed, you can now create a QR code from a text. In the terminal, enter the following command:

qrencode -o qr_code.png 'Your text here'

Replace 'Your text here' with the desired text you want to encode. This command will save the generated QR code as a PNG image named qr_code.png in the current directory.

Part 2: Reading a QR code

Reading a QR Code from Its Image To decode and read the content of a QR code from its image, we will use the zbarimg command-line tool. Follow these steps:

Step 1: Install zbar:

Ensure that zbar is installed on your Linux system. To install it, open the terminal and run the following command:

dnf install zbar

Step 2: Read the QR code:

Once zbar is installed, navigate to the directory where your QR code image is located. In the terminal, run the following command:

zbarimg -q --raw qr_code.png

This command will decode the content of the specified QR code image (qr_code.png) and display it in the terminal. The -q flag suppresses unnecessary output, and the --raw flag is used to retrieve the raw content without any metadata.

Feel free to experiment with different types of data and explore additional features and options provided by the qrencode and zbarimg tools.

If you have any queries feel free to reach out at sumitdhattarwal4444@gmail.com

--

--