Is it possible to create a QR code using text

asciiqr-codeutf-8

QR codes I have seen are mostly image files. But can you create QR codes using plain text?

For example ASCII and UTF-8 have black boxes as characters. Can I use those together with spaces to create a QR code?

Best Answer

Yes! There is a utility called qrencode that can render these for you.

The only really important factor for a QR code is that the 2D array has "darker" and "ligher" pixels / segments. It can be colored too, though contrast can start to be an issue.

ASCII

Your ability to read this QR code will likely depend on the camera's resolution, distance, and the software you're using.

qrencode -t ASCIIi 'https://superuser.com/questions/1420001/is-it-possible-to-write-a-qr-code'

Note: I used -t ASCIIi (Inverted ASCII) because my terminal is White-on-Black.

ASCII QR Code

ANSI

This mode works by setting the background color to black or white, and printing a number of space characters.

qrencode -t ANSI 'https://superuser.com/questions/1420001/is-it-possible-to-write-a-qr-code'

ANSI QR Code

Some of the raw characters written to the terminal are shown below, these are ANSI escape codes. An "escape" character has a value of 0x1b and can often be written as \e.

  • \e[40m sets the background color to black
  • \e[47m sets the background color to white
  • 0x20 is an ASCII space

ANSI QR Code Raw

UTF-8

There is also a UTF-8 mode (-t UTF8). This mode uses the "half block" characters to increase the density, and cut the line count by half.

  • ▀ - U+2580 / Upper Half Block
  • ▄ - U+2584 / Lower Half Block
  • █ - U+2588 / Full Block

Screenshot from @grawity (thanks)

qrencode -t UTF8 'https://superuser.com/questions/1420001/is-it-possible-to-write-a-qr-code'
qrencode -t ANSIUTF8 'https://superuser.com/questions/1420001/is-it-possible-to-write-a-qr-code'

UTF-8 QR Code

Related Question