Skip to content

QR Code Version 1 to 5 generation and drawing on terminal, can also output bitmap and SVG.

License

Notifications You must be signed in to change notification settings

oAGoulart/qrcode

Repository files navigation

Command-line QR Code generator

Static Badge GitHub Release GitHub License DOI

Objective: Model 2, from version 1 to 5, byte/num/alpha modes, with EC level L, as specified in ISO/IEC 18004:2024. There are no dependencies, generator can be built from code on any platform. Output inline (stdout), bitmap, or vectors (svg).

Available generation:

Version 1 2 3 4 5
Capacity (codewords) 17 32 53 78 106

Note

Generator will auto-select the smallest Version possible. Unless option -u specified. Here, codeword refers to a full byte. Numeric encoding uses up to 10-bits for 3 digits (~58% reduction). Alphanumeric encoding uses up to 11-bits for each pair of characters (~31% reduction).

Pre-generated lookup tables:

  1. Reed-Solomon EC generator polynomials.
  2. Galois field of 256 (285 primitive) log and anti-log table.
  3. Placement index of each data and error correction bit on the encoding region.

Usage

Options available:

Usage: qrcode [OPTIONS] <data to encode>
OPTIONS:
  --nocopy     omit copyright header from inline printing
  --noinline   do not print any inline code, disregards --raw
  --optimize   reduce data size, encode numeric, alphanumeric, byte
                 segments separately (if any)
  --raw        print generated code with chars 1, 0 (no box-chars)
  --verbose    print runtime information for generated values
  --version    show generator's version and build information
  -m <uint>    force choice of mask <0-7>, regardless of penalty
  -u <uint>    scale image output <1-30> times
  -s <uint>    force use of version <1-5> code (or lower, if
                 used with --optimize)
  -B <string>  create bitmap file with generated code
  -K <string>  create scalable vector image, disregards -s

Building and binaries

Latest (stable) releases can be found at this repo's Releases. To build this project, use make. Otherwise, as long as your system has Clang and Python, you may run Makefile's build commands manually.

Caution

This repo's master branch may or may not contain uncompilable, unstable code. It's recommended that you select the latest tag release, unless you wish to collaborate with code.

Build tools used for binaries:

Tool Ubuntu 22.04
amd64/x86
(WSL 2)
Windows 11
amd64
(MSYS2)
FreeBSD 14.3
x86
(VM)
macOS 14
aarch64
(VM)
OmniOS r151054
amd64
(VM)
GNU Make 4.3 4.4 4.4.1 4.4.1 4.4.1
Clang 14.0.0 20.1.8 19.1.7 15.0.0 20.1.7
Python 3.10.12 3.12.6 3.11.13 3.13.7 3.13.3
status 🟩 🟩 🟩 🟩 🟩

Examples

1. Inline printing

Command-line:

qrcode oagoulart.github.io/rambles/keep-thyself-credible

Output:

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

Tip

Using a line-height of 1em (i.e. line height is equal to font size) will remove the unintended vertical spacing seen in the output above. Some fonts may require a slight different value between 1 +/- .25. You can also try value normal.

2. Bitmap generation

Command-line:

qrcode -s 6 -B gen.bmp oagoulart.github.io/rambles/keep-thyself-credible

Output:

QR Code

3. Vector graphics generation

Command-line:

qrcode -K gen.svg oagoulart.github.io/rambles/keep-thyself-credible

Output:

QR Code

Roadmap

Planned features:

  1. higher EC levels (TBD)
    • lookup tables
    • codewords splitting
  2. higher Version codes (TBD)

Disclaimer

QR Code, iQR Code SQRC and FrameQR are registered trademarks of DENSO WAVE INCORPORATED in Japan and in other countries.

ISO/IEC 18004:2024 - Information technology — Automatic identification and data capture techniques — QR Code bar code symbology specification is © ISO/IEC 2024 – All rights reserved.

Further reading

  1. BMP file format
  2. Scalable Vector Graphics (SVG) 1.1 (Second Edition)

About

QR Code Version 1 to 5 generation and drawing on terminal, can also output bitmap and SVG.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors 2

  •  
  •