Usage

Basic usage

Encode a string in a QR code
qrtool encode "QR code" > output.png
Output
Figure 1. Generate this image
Decode a QR code from this image
$ qrtool decode output.png
QR code

Output formats

Use -t option to change the format of the generated image.

List of supported formats
  • png (default)

  • svg

  • eps (Encapsulated PostScript)

  • pic (PIC markup language)

  • ansi (to the terminal using 4-bit ANSI escape sequences)

  • ansi256 (to the terminal using 8-bit ANSI escape sequences)

  • ansi-true-color (to the terminal using 24-bit ANSI escape sequences)

  • ascii (to the terminal as ASCII string)

  • ascii-invert

  • unicode (to the terminal as UTF-8 string)

  • unicode-invert

Encode in a QR code and output as a SVG image
qrtool encode -o output.svg -t svg "QR code"
Output
Figure 2. Generate this image
Output to the terminal as UTF-8 string
qrtool encode -t unicode "QR code"

Types of QR code

Use --variant option to change the variant of the generated QR code. The variant is normal (default), micro (Micro QR code), or rmqr (rMQR code).

Encode a string in a Micro QR code
qrtool encode --variant micro "QR code" > output.png
Output
Figure 3. Generate this image
Encode a string in a rMQR code
qrtool encode --variant rmqr "QR code" > output.png
Output
Figure 4. Generate this image

Colored output

Use --foreground and --background options to change the foreground and background colors of the generated image. These options takes a CSS color string such as brown, #a52a2a or rgb(165 42 42). The default foreground color is black and the background color is white of CSS’s named colors.

Encode in a QR code with the specified colors
qrtool encode --foreground brown --background lightslategray "QR code" > output.png
Output
Figure 5. Generate this image
Note that lossy conversion may be performed depending on the color space supported by the method to specify a color, the color depth supported by the output format, etc.

Supported input image formats

qrtool decode supports decoding a QR code from various image formats.

To support decoding from SVG image, the decode-from-svg feature must be enabled at compile time. Note that the SVG image is rasterized before scanning.

Image formats other than PNG can be disabled by disabling the default feature, and can be enabled individually.

Use -t option to specify the image format. If this option is not specified, the image format is determined based on the extension or the magic number.

Input
Figure 6. Input this WebP image
Decode a QR code from the WebP image
$ qrtool decode input.webp
QR code
# or
$ qrtool decode -t webp input.webp
QR code

Generate shell completion

completion subcommand generates shell completions to standard output.

The following shells are supported
  • bash

  • elvish

  • fish

  • nushell

  • powershell

  • zsh

Example
qrtool completion bash > qrtool.bash

Integration with other programs

Both qrtool encode and qrtool decode can read from standard input and output to standard output.

Optimize the output image

The image output by qrtool encode is not optimized. For example, a PNG image is always output as the 32-bit RGBA format. If you want to reduce the image size or optimize the image, use an optimizer such as oxipng or svgcleaner.

Optimize the output PNG image
qrtool encode "QR code" | oxipng - > output.png
Optimize the output SVG image
qrtool encode -t svg "QR code" | svgcleaner -c - > output.svg
If the optimize-output-png feature is enabled, you can also use --optimize-png option and --zopfli option of this command to optimize output PNG image.

Reading and writing unsupported image formats

If you want to save the encoded image in an image format other than PNG or SVG, or decode an image in an unsupported image format, convert it using a converter such as ImageMagick or Inkscape.

Raster formats

Encode in a QR code and output as a JPEG 2000 image
echo 'print("Hello, world!")' > main.py
cat main.py | qrtool encode | magick png:- output.jp2
Decode a QR code from this image
$ magick output.jp2 png:- | qrtool decode | bat -pp -l py
print("Hello, world!")

Vector formats

Encode in a QR code and output as a PDF file
echo 'puts "Hello, world!"' > main.rb
cat main.rb | qrtool encode -t svg | inkscape -p -o output.pdf
Decode a QR code from this file
$ inkscape -o - --export-type svg output.pdf | qrtool decode
puts "Hello, world!"

1. CUR is also supported.
2. SVGZ is also supported.