banner image

QR codes

There's a qrcode python package:

pip install qrcode

Which provides a command-line program qr.

It prints ascii-art QR codes:

QR code printed from terminal

This is made using the block elements part of unicode. I fondly remember old MS-DOS programs which made great use of block elements and box drawing.

$ echo qr | qr

█████████████████████████████
█████████████████████████████
████ ▄▄▄▄▄ █▄  ▀██ ▄▄▄▄▄ ████
████ █   █ █▀▄▀▀ █ █   █ ████
████ █▄▄▄█ █ ▀▀▀▄█ █▄▄▄█ ████
████▄▄▄▄▄▄▄█ ▀ ▀ █▄▄▄▄▄▄▄████
████▄█▀▀▄█▄  █▄ ▀▄▄ ▄▄▀█▄████
████▀▀█▀▄▀▄█▄▀ ▄█▀ ▄  ▄ █████
████▄▄▄▄█▄▄█  ██   ███▄▄▄████
████ ▄▄▄▄▄ █▄ █▀ ▄█▀█ ▄ ▀████
████ █   █ █▄ ▀ ▀█▄ ▄▀▄  ████
████ █▄▄▄█ ███ ▄█▀ ▄ ▄ ██████
████▄▄▄▄▄▄▄█▄███▄▄▄███▄█▄████
█████████████████████████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

The colors in this example are inverted, as it expects a light-on-dark terminal color scheme (which this blog isn't).

The obvious next step

Make a QR code which contains the image of a QR code:

$ echo qr | qr | qr

A large QR code

I cheated slightly here by alias qr='qr --error-correction=L --optimize=0' to make the QR code smaller.

The obvious next step

$ echo qr | qr | qr | qr > qr-cubed.png

A very large QR code

I have taken this too far.

Bonus: The QR Clock:

while sleep 1; do
  date --rfc-3339=seconds \
  | qr --optimize 0 > /tmp/a.png \
  && clear \
  && COLUMNS=300 img2txt --width=90 /tmp/a.png;
done