Acknowledgement
My primary source for this article is:
Howtogeek.com.
Generate QR Code on Linux
QR codes (Quick Response codes) offer a practical means to share a vast amount
of information in a compact format. With the ubiquity of cellphones, virtually
everyone possesses a device capable of scanning these codes. Numerous free
software applications facilitate QR code scanning, negating the need for
additional hardware or costly software.
The technical prowess of QR codes lies in their capacity to store a larger
volume of data compared to barcodes. A distinct feature of QR codes is their
design, allowing scanners to ascertain the code's orientation. This capability
ensures that the scanner can process the code irrespective of its alignment.
This inherent property made QR codes invaluable in streamlining processes in
manufacturing environments, particularly in tracking inventories and components.
While online QR code generators abound, many come with privacy concerns. Some
generators retain the data inputted, potentially misusing sensitive information,
such as personal contact or Wi-Fi credentials. For enhanced data security, it's
advisable to employ command-line tools like qrencode. This tool not only ensures
data remains under the user's control but also enables the programmatic
generation of QR codes through scripts and aliases.
Installing qrencode
qrencode
is a versatile, fast, and richly-featured QR code generator. It
provides a library that can be linked into your own programs to encapsulate the
QR generation technologies into your own applications. We'll be using the
command line utility for our purposes.
# Debian/Ubuntu
sudo apt-get install qrencode
# Fedora
sudo dnf install qrencode
# Arch
sudo pacman -S qrencode
qrencode Parameters
-
-s <size in pixels>
: This sets the size of the blocks in the QR pattern. The
number sets the pixels for the length of one side of a block.
-
-l <level of error-correction>
(L
, M
, Q
, H
): The options we can use
are L
for low, M
for medium, Q
for quite high, and H
for highest. The
different levels of error-corrections can code with different amounts of
damage or illegibility.
-
-t <image type>
(PNG
, SVG
, ANSI
, EPS
): Set the image type of the
output image that is to be generated.
-
-o <output-file>
: The filename for the generated image. By default, the
program generates a PNG image. This can be changed using the -t
option.
-
--foreground=<hex color>
: You can set the foreground color of the image
using this flag. Note that the color is not prefix with a "#".
-
--background=<hex color>
: You can set the background color of the image
using this flag. Note that the color is not prefix with a "#".
Encode Plain Text
To encode plain text into the QR code we just provide it as the argument to the
program.
qrencode -s 6 -l H -o "text.png" \
"This type of QR holds plain text."
Encode Geo Location
To encode a location on to a QR code we must start with geo:
and use comma
separated coordinates.
qrencode -s 6 -l H -o "location.png" "geo:51.1859,-1.23552"
Encode Phone Number
To encode a phone number on to a QR code we must start with tel:
and provide
just digits following it.
qrencode -s 6 -l H -o "phone.png" "tel:5555555555"
Encode Email
To encode an email on to a QR code we must start with mailto:
and provide the
details in the following way.
qrencode -s 6 -l H -o "email.png" \
"mailto:abc@xyz.com?subject=Linux&body=Linux articles are cool."
Encode URL
To encode a URL on to a QR code we must just include "https://" in the argument.
qrencode -s 6 -l H -o "url.png" "https://suchicodes.com"
Encode SMS Message
To encode an SMS message on to a QR code we must start with smsto:
and provide
the phone and message using a comma to separate them.
qrencode -s 6 -l H -o "sms.png" "smsto:5555555555,SMS body of message."
Encode WiFi Network
To encode a WiFi network on to a QR code we must start with WIFI:
and provide
the details using semicolon ;
separated values.
-
T
: The type of security. This can be WEP, WPA, or WPA2. Note there is a
colon between the "T" and the security value, and there is a semicolon " ; "
after the security setting.
-
S
: The Service Set ID (SSID) of the Wi-Fi network. Note there is a colon
between the "S" and the SSID, and there is a semicolon " ; " after the SSID.
-
P
: The password or security key of the Wi-Fi network. Note there is a colon
between the "P" and the security key, and are two semicolons " ;; " after the
security key.
qrencode -s 6 -l H -o "wifi.png" "WIFI:T:WPA;S:<SSID>;P:<PSWD>;;"