Swift CLI tool to generate stylized QR codes (SVG and PNG) from data or text.
Swift Package library: QRGen
OVERVIEW: Generate an (optionally stylized) QR code image from a given input.
USAGE: QRGen code [OPTIONS ...] <input type> <input> [<output path>]
ARGUMENTS:
<input type> The type of input used in the <input> argument.
(values: text | textFile | bytes)
<input> The input used to build the QR code's data. For input
type "text" specify a string, for "textFile" and
"bytes" a file path or "-" for stdin.
<output path> Directory or file path where to write output files to.
(default: directory of input file or working directory)
GENERATOR OPTIONS:
-l, --level (L | M | Q | H) The QR code's correction level (parity). (default: M)
--min <version 1-40> Minimum QR code version (i.e. size) to use. Not
supported with "--coreimage" flag. (default: 1)
--max <version 1-40> Maximum QR code version (i.e. size) to use. Error is
thrown if the supplied input and correction level would
produce a larger QR code. (default: 40)
-o, --optimize Try to reduce length of QR code data by splitting text
input into segments of different encodings. Not
supported with "--coreimage" flag.
--strict Strictly conform to the QR code specification when
encoding text. Might increase length of QR code data.
No effect with "--coreimage" flag.
STYLE OPTIONS:
-s, --style (standard | dots | holes | liquidDots | liquidHoles)
The QR code's style. (default: standard)
-m, --pixel-margin <percentage> Shrink the QR code's individual pixels by the specified
percentage. Values >50 may produce unreadable results.
(default: 0)
-r, --corner-radius <percentage> Specify corner radius as a percentage of half pixel
size. Ignored for "standard" style. (default: 100)
-a, --style-all Apply styling to all pixels, including the QR code's
position markers.
GENERAL OPTIONS:
-p, --png Additionally to the SVG output file, also create an
unstyled PNG file.
--coreimage Use built-in "CIQRCodeGenerator" filter from CoreImage
to generate QR code instead of Nayuki implementation.
--no-shape-optimization Add one shape per pixel to the SVG instead of combining
touching shapes. This may result in anti-aliasing
artifacts (thin lines) between neighboring pixels when
viewing the SVG!
--version Show the version.
-h, --help Show help information.
EXAMPLES:
QRGen code text "http://example.org" example
QRGen code -l Q textFile data.txt
QRGen code --level L -s liquidDots -r 80 -a bytes event.ics
OVERVIEW: Generate different kinds of content for a QR code.
USAGE: QRGen content <subcommand>
GENERAL OPTIONS:
--version Show the version.
-h, --help Show help information.
SUBCOMMANDS:
wifi QR code content for WiFi network information.
event QR code content for a calendar event in the vEvent format.
geo QR code content for geographical coordinates.
See 'QRGen help content <subcommand>' for detailed help.
Instead of building the tool yourself, you can download a compiled binary for macOS and Linux from the latest release.
The Linux binaries are statically linked with the Swift stdlib and thus no installation of Swift is required.
On Linux, the --coreimage
and --png
options are removed due to Apple's CoreImage
framework being unavailable.
To build the package, the Swift toolchain version 5.5 or higher needs to be installed.
- For macOS either download Xcode from the AppStore or run
xcode-select --install
to just get the Command Line Tools.
Swift 5.5 requires at least Xcode 13 and macOS 11.3 Big Sur. - For Linux download Swift from swift.org for your distro and follow the installation guide further down the page.
Build the Swift Package and copy executable to bin/
:
$ make
Automatically install executable into /usr/local/bin/
:
$ make install
Open the Xcode project and go to Product > Build (⌘B).
After that, either run it directly from bin/pwgen
or install it to your PATH location by manually copying it, e.g.:
$ cp bin/QRGen /usr/local/bin/