QR Code generator for Zig
  • Zig 99.8%
  • C 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-09-23 19:28:46 +02:00
examples/images added quiet zone as command line argument 2026-09-21 23:26:51 +02:00
src switched to new translate c interface 2026-09-22 20:44:12 +02:00
.gitignore initial commit 2026-09-21 22:40:44 +02:00
build.zig make the executables individual steps 2026-09-23 19:28:46 +02:00
build.zig.zon updated zigimg dependency 2026-09-22 20:26:04 +02:00
LICENSE.md initial commit 2026-09-21 22:40:44 +02:00
README.md make the executables individual steps 2026-09-23 19:28:46 +02:00

QR Code - Zig

Bringing QR Codes to Zig.

This package uses the QR Code generator of nayuki.

Supported Zig version: 0.16.0

Barcode Type Example License Read Write Link to Repository Link to Website
QR Code MIT ✅ QR-Code-generator Project Nayuki - QR Code generator library

Running zig build will most likely fail due to a unknown issue that has something to do with using the writeToFile function of zigimg. Please build with zig build -Doptimize=ReleaseFast!

Usage

This package offers the following:

  • a command line application for generating QR Codes
  • the libqrcodegen.a and qrcodegen.h files
  • a Zig module qrcode that wraps libqrcodegen

Command Line Application

Requires Zig version 0.16.0

First clone this repository and then change into its local directory:

git clone https://codeberg.org/r4gus/qrcode-zig.git
cd qrcode-zig

Next, run the following to build the command line application:

zig build cla -Doptimize=ReleaseFast

Afterwards you can find the application under zig-out/bin/, the library under zig-out/lib and the corresponding header file under zig-out/include.

Finally, run the following command as a test

./zig-out/bin/qrcode "https://eurozig.eu" --image png --file zig.png -s 16

The --image option allows you to specify the image type. Currently, only png is supported. As an alternative you can print the generated qr code to the console by leaving out the --image argument.

The --file option must be used in conjunction with the --image option and allows you to specify the name of the file to write the image to.

Finally, the -s or --scale option allows you to specify the scale of each qr code module in pixels.

Zig Module

To use this package (meaning the qrcode module or libqrcodegen.a) within your own application, first add this package as a dependency to your build.zig.zon:

Getting Started

zig fetch --save git+https://codeberg.org/r4gus/qrcode-zig.git

Next add the module to your build.zig:

const qrcode = b.dependency("qrcode_zig", .{});
exe.root_module.addImport("qrcode", qrcode.module("qrcode"));

or link the static library with:

my_mod.linkLibrary(qrcode.artifact("qrcodegen"));

Using the module

First import the qrcode module:

const qrcode = @import("qrcode");

TODO