QR Code Generation in Linux

There are a wide array of websites and programs that enable the user to generate QR codes. The problem with the majority of these utilities, however, is that they are either difficult to use, or cannot be used for free.

In this demo, I will demonstrate how to quickly and efficiently generate QR codes using the Linux command line, and a few simple lines of bash scripting.

 

Source Code:

#!/bin/bash
echo "URL:"
read URL
if [ sudo dpkg -l qrencode ]; then
    qrencode -s 6 -l H -o "URL.png" $URL
    sudo chmod 777 URL.png
else
    sudo apt install qrencode -y
    qrencode -s 6 -l H -o "URL.png" $URL
    sudo chmod 777 URL.png
fi
 

Instructions:

In order to utilise the above bash script, the first step is simply to save the above code to any file with the .sh file extension. I personally use the name QR.sh because it is clear and appropriate.

Next, one can simply open any Unix command line, log into root, then use the ./ function in order to proceed. For example:

./QR.sh

At this point, the user will be prompted to enter whatever text they want to convert into a QR code. For example, typing “https://www.garethgummow.com” yields the following QR code as the end result:

Dynamic QR:

Dynamic QR code generation is possible using this code, and can be achieved without any additional steps.

If one is in possession of the URL a given QR code links to, then one has the ability to change what that URL is hosting. The ability to do this is what makes a QR code ‘Dynamic’.

One use-case for this would be having a QR code that links to a resume or portfolio that is frequently updated, which by extension ensures the information linked to by a QR code remains up-to-date.

Another option is to create multiple QR codes that each go to their own separate URLs, with each of these then redirecting to one singular URL. This allows one to extract information like when and where a code was scanned, which can be useful for gathering information like how often and within what contexts one’s QR codes are being scanned by users. Simply use a different URL for each QR code, make sure each URL redirects to the same central location, then check if and when a particular URL has been accessed to determine which codes have or have not been scanned.

Previous
Previous

LaTeX: Document Generation

Next
Next

Neovim Configurations