Is it possible to create a QR code using text?

115

34

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?

Murat Kaçiran

Posted 2019-04-01T14:32:14.273

Reputation: 1 005

7Is there a specific project this is for? I'm just curious – Ben Leggiero – 2019-04-02T03:35:51.170

6@BenLeggiero Thank you for your question. I don't have a certain project but I thought it would be handy to know the existence of such QR codes. For example, you can put those in a bio on a forum if the forum doesn't support profile pictures, and many more advantages. – Murat Kaçiran – 2019-04-02T10:19:37.550

At a small enough font size, you don't even need the black boxes! – Paul D. Waite – 2019-04-03T16:27:15.657

Answers

171

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

Attie

Posted 2019-04-01T14:32:14.273

Reputation: 14 841

4Don't forget -t UTF-8 mode, which uses the "box drawings" characters that OP mentions? – user1686 – 2019-04-01T15:00:39.303

9https://i.imgur.com/WQYkxYm.png https://i.imgur.com/KeDVJ16.png – this uses "half block" characters , with optional colors to increase contrast only. (They're from Unicode 1.1 and date all the way to IBM DOS; surprised there's still any terminal that cannot render those...) – user1686 – 2019-04-01T15:04:48.730

PuTTY 0.71 on Windows 10 with Consolas works well. Either recent Windows versions improved the Consolas font significantly, or recent PuTTY releases improved its "fallback font" behavior, or both. – user1686 – 2019-04-01T15:14:32.070

Hi, thank you for answering! I know how to work with a console, however will this work on windows? Also is there an installer? The one I found only has a gui with restricted feautures. I'm not amazing in computers, sorry. – Murat Kaçiran – 2019-04-01T15:28:50.510

1

No problem! It should work on Windows.. the project page mentions a Win32 port, that has an installer available for download... it looks like it was last updated in Feb 2015.

– Attie – 2019-04-01T20:57:15.770

@grawity Mine doesn't render well aswell. Only ASCII works for me. Is it because windows terminals are restricted for all characters? Powershell and CMD don't work. – Murat Kaçiran – 2019-04-02T11:30:02.360

I can't edit my comment anymore so I put it here. Git bash works fine now! – Murat Kaçiran – 2019-04-02T11:36:27.453

7@MuratKaçiran: Powershell and CMD are just command interpreters (shells), they both use the same "Windows Console" as the terminal. It too has received significant improvements in Win10.18xx. In the past, it did not support UTF-8 at all. It could do Unicode via UTF-16 with suitably written programs, but those programs had to deliberately use the special Unicode mode. If the program didn't do that, all you get is the MS-DOS era cp437 codepages... In that situation, qrencode -t UTF8 | iconv -f utf8 -t cp437 may still work, as the same box drawings also existed back then. – user1686 – 2019-04-02T11:46:36.083

Also curious, why does -t UTF8 generate a slightly different image from the others? The top two rows are mostly inverted, with slight differences on the right – phflack – 2019-04-03T13:36:27.953

1

Good question... this doesn't happen for me when running the command again... Differences visible here. Additionally the black pixels in the top left mean that the QR code is technically invalid... the fact that they both scan and the same data is extracted shows the robustness of a QR code.

– Attie – 2019-04-03T14:23:11.393

6To my surprise, the QR reader app on my iphone successfully read all these off my screen, including the ASCII # one. +1. – Digital Trauma – 2019-04-03T17:10:15.850

3@Attie: Oh, I probably had accidentally selected some text so it shows part of the line in reverse-text. – user1686 – 2019-04-04T10:30:14.003