Pure python QR Code generator

From LinuxReviews
Jump to navigationJump to search
Linuxreviews-qr-code.png

The Pure python QR Code generator is a QR-code library which comes with a command-line utility capable of making images with QR codes in text, PNG and SVG formats. It is a handy little tool to use if you ever need to generate images with QR codes.

Features And Usability

The Pure python QR Code generator comes with a small binary called qr which is symlinked from qrcode.

The qr manual page[1] lists --optimize=, --factory= and --error-correction= as available options.

The qr utility is meant to be executed from a terminal. It will by default create a QR-code of any argument given to it using pure text:

Qr-linuxreviews.jpg
The output of qr "https://linuxreviews.org/".

qr can also be used to create PNG and SVG images. This is done by piping it to a file. qr will by default create a PNG image if it detects that it is being piped to a file.

qr "https://linuxreviews.org/" > linuxreviews-qr-code.png creates a 300x300 pixels large image called linuxreviews-qr-code.png with the URL to this website.

Linuxreviews-qr-code.png
A PNG image with a QR code to this site generated by the example above. There is, as you can see, a lot of whitespace around the actual QR code so you may want to crop images created by qr with GIMP or KolourPaint

qr can also generate SVG images using the --factory= switch. Three SVG options are available: svg-path, svg and svg-fragment. You want to use the svg-path option to create SVG images. This will output the SVG data to the terminal qr is running in. You can save the SVG to a file by piping > it to a file:

qr --factory=svg-path "https://linuxreviews.org/" > linuxreviews-qr-code.svg

Creating an alias with alias qrsvg='qr --factory=svg-path' in $HOME/.bashrc is probably easier than remembering that command-line option.

Advanced Use

Pure python QR Code generator is primarily written to be a library other applications can take advantage of. It is, as such, capable of much more than the qr utility allows you to do. See the pypi.org/project/qrcode/ for some Python programming examples. You will have to write a short Python program which imports the qrcode library to create QR code images with other colors, sizes etc.

Installation

The Pure python QR Code generator is available as a package named python3-qrcode on Fedora. It can be installed on other distributions using pip with pip install qrcode[pil].

Links

The Pure python QR Code generator has a pypi page at pypi.org/project/qrcode/ and a GitHub repository at github.com/lincolnloop/python-qrcode/.

Notes

Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.