LinuxCommandLibrary

qrencode

Generate QR Code from text or data

TLDR

Convert a string to a QR code and save to an output file

$ qrencode [[-o|--output]] [path/to/output_file.png] [string]
copy

Convert an input file to a QR code and save to an output file
$ qrencode [[-o|--output]] [path/to/output_file.png] [[-r|--read-from]] [path/to/input_file]
copy

Convert a string to a QR code and print it in terminal
$ qrencode [[-t|--type]] ansiutf8 [string]
copy

Convert input from pipe to a QR code and print it in terminal
$ echo [string] | qrencode [[-t|--type]] ansiutf8
copy

SYNOPSIS

qrencode [OPTIONS] [STRING]

If STRING is provided, it is encoded into a QR Code. If STRING is omitted, qrencode reads the input data from standard input (stdin). The generated QR Code can be output to a file or displayed directly in the terminal, depending on the chosen options.

PARAMETERS

-o FILE
    Specifies the output file path. If not provided, output goes to stdout (for image formats) or stderr (for ANSI/ASCII).

-s SIZE
    Sets the pixel size of each module (dark or light square) in the QR Code. Default is 3.

-l LEVEL
    Defines the error correction level: L (low, 7%), M (medium, 15%), Q (quartile, 25%), or H (high, 30%). Default is L.

-v VERSION
    Sets the QR Code version (size). Versions range from 1 (21x21 modules) to 40 (177x177 modules). Auto-detection is used if not specified.

-m MARGIN
    Sets the quiet zone margin width around the QR Code in modules. Default is 4.

-t TYPE
    Specifies the output format: PNG, SVG, EPS, ANSI (color terminal), ASCII (monochrome terminal), or UTF8 (UTF-8 characters for terminal). Default is PNG.

-8
    Encodes input STRING as UTF-8. Useful for non-ASCII characters.

-r
    Treats the input data as raw binary, preventing internal character encoding conversions.

-h
    Displays the help message and exits.

-V
    Displays the version information and exits.

DESCRIPTION

qrencode is a powerful command-line utility for generating QR Code images from given input data. It is built upon the libqrencode library, making it a reliable tool for quickly creating QR codes directly from the terminal. The command offers extensive customization options, allowing users to control parameters such as the error correction level, QR Code version, module size, and quiet zone margin.

It supports various output formats, including common image types like PNG, SVG, and EPS, as well as text-based representations like ANSI and ASCII art for terminal display. This flexibility makes qrencode suitable for a wide range of applications, from embedding URLs and contact information into images to generating codes for automated scripts or documentation. Data can be supplied as a command-line argument or read from standard input, enhancing its integration with other Linux tools and shell scripting.

CAVEATS

Data Capacity Limits: The amount of data that can be encoded in a QR Code is limited by its version and error correction level. Higher error correction levels reduce data capacity.

Scanning Reliability: Extremely large or complex QR codes, or those with very small module sizes, might be difficult for some scanners to read, especially on lower-resolution displays or prints.

Terminal Output: ANSI/ASCII output formats are dependent on the terminal's capabilities and font settings for proper display and scannability. Color ANSI output might not be supported everywhere.

USAGE EXAMPLES

1. Encode a simple URL to PNG:
qrencode -o myurl.png "https://www.example.com"

2. Display QR code in terminal (ANSI):
qrencode -t ANSI "Hello, World!"

3. Encode data from a file with high error correction:
cat input.txt | qrencode -l H -o from_file.png

4. Generate a large QR code for contact info:
qrencode -s 5 -v 10 -o contact.svg "MECARD:N:John Doe;TEL:1234567890;EMAIL:john.doe@example.com;;"

HISTORY

The qrencode command is part of the libqrencode library, which was developed by Kentaro Fukuchi starting around 2008. The library aimed to provide an open-source and portable C library for encoding data into QR Codes, adhering to the ISO/IEC 18004 standard. qrencode serves as the primary command-line interface to this robust library, making QR code generation widely accessible on Linux and Unix-like systems for scripting, automation, and general use. Its continuous development has ensured compliance with QR Code standards and support for various output formats.

SEE ALSO

zbarimg(1): A command-line tool for scanning and decoding bar codes and QR codes from image files or video streams., convert(1): (ImageMagick) A versatile command-line tool for converting images between different formats and performing various image manipulations., printf(1): Formats and prints data, often used to pipe string data to qrencode's standard input.

Copied to clipboard