qrtool is a command-line utility for encoding or decoding QR code.
cargo install qrtool
OS | Package manager | Command |
---|---|---|
Any | Homebrew | brew install qrtool |
Any | Nix | nix-env -iA nixpkgs.qrtool |
Arch Linux | Pacman | pacman -S qrtool |
openSUSE | Zypper | zypper install qrtool |
The release page contains pre-built binaries for Linux, macOS and Windows.
Please see BUILD.adoc.
Encode a string in a QR code:
qrtool encode "QR code" > output.png
Generate this image:
Decode a QR code from this image:
$ qrtool decode output.png
QR code
Use -t
option to change the format of the generated image.
The format is:
png
(default)svg
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 to a SVG image:
qrtool encode -o output.svg -t svg "QR code"
Generate this image:
Generate a PDF file from the PIC code:
qrtool encode -t pic "QR code" \
| awk 'BEGIN { print ".vs 0\n.po 0\n.PS" } END { print "scale = 25.4 * 3\n.PE" } { print }' \
| groff -Tpdf -p -P-p3i,3i \
> output.pdf
Output to the terminal as UTF-8 string:
qrtool encode -t unicode "QR code"
Use --variant
option to change the variant of the generated QR code. The
variant is normal
(default) or micro
(Micro QR code).
qrtool encode -v 3 --variant micro "QR code" > output.png
Generate this image:
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.
qrtool encode --foreground brown --background lightslategray "QR code" > output.png
Generate this image:
Colored output is also available when the output format is any ANSI escape sequences:
qrtool encode -t ansi-true-color --foreground brown --background lightslategray "QR code"
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.
qrtool decode
supports decoding a QR code from the following 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 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-completion
option generates shell completions to standard output.
The following shells are supported:
bash
elvish
fish
nushell
powershell
zsh
Example:
qrtool --generate-completion bash > qrtool.bash
Both qrtool encode
and qrtool decode
can read from standard input and
output to standard output.
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.
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.
Read Cargo.toml
from standard input and save the encoded result as a XPM
image:
cat Cargo.toml | qrtool encode | magick png:- output.xpm
Decode this image and print the result using bat
:
magick output.xpm png:- | qrtool decode | bat -l toml
Read a string from standard input and save the encoded result as an EPS image:
echo "The quick brown fox jumps over the lazy dog." \
| qrtool encode -t svg \
| inkscape -p -o output.eps
Decode this image and print the result to standard output:
$ inkscape -o - --export-type svg output.eps | qrtool decode
The quick brown fox jumps over the lazy dog.
Please see the following:
The upstream repository is available at https://github.com/sorairolake/qrtool.git.
The source code is also available at:
Please see CHANGELOG.adoc.
Please see CONTRIBUTING.adoc.
This program is inspired by qrencode
and zbarimg
.
Copyright © 2022–2024 Shun Sakai and other contributors (see AUTHORS.adoc)
- This program is distributed under the terms of either the Apache License 2.0 or the MIT License.
- Some files are distributed under the terms of the Creative Commons Attribution 4.0 International Public License.
This project is compliant with version 3.2 of the REUSE Specification. See copyright notices of individual files for more details on copyright and licensing information.