This is a simple QR code generator written in C. It reads a string from arguments and outputs an image or text.
- Mode detection (numeric, alphanumeric, binary, kanji)
- Auto version selection
- Custom fg/bg color
- Boost EC level automatically to fit version
- Supported output formats:
- Image: PNG, BMP, Targa, HDR, JPEG, farbfeld
- Text (using Unicode block characters)
- HTML
- Micro QR code (μQR)
- More encoding modes
- Multi-encoded QR codes
iconv
(glibc)
See qr --help
for more information.
Example program:
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <qr/qr.h>
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
int main() {
struct qr_alloc alloc = QR_ALLOC(malloc, realloc, free);
struct qr qr;
memset(&qr, 0, sizeof(qr));
const char *error = NULL;
if (!qr_encode_utf8(&qr, alloc, "Hello world!", QR_MODE_AUTO, QR_VERSION_AUTO, QR_ECL_MEDIUM, &error)) {
eprintf("Failed to encode data for QR code: %s\n", error);
return 1;
}
if (!qr_prepare_data(&qr, &error)) {
eprintf("Failed to prepare QR code data: %s\n", error);
return 1;
}
if (!qr_render(&qr, &error, QR_MASK_AUTO)) {
eprintf("Failed to render QR code: %s\n", error);
return 1;
}
struct qr_pos pos;
for (pos.y = 0; pos.y < qr.output.size; pos.y++) {
for (pos.x = 0; pos.x < qr.output.size; pos.x++) {
printf("%s", qr_bitmap_read(qr.output, pos) ? "##" : " ");
}
printf("\n");
}
qr_close(&qr);
return 0;
}
After running meson install
, compile with
gcc main.c -o main -Wl,-rpath,/usr/local/lib -lQR -I/usr/local/include
sudo apt install build-essential meson
Then follow the instructions below
Find dependencies listed above in your package manager or elsewhere:
git clone https://github.com/mekb-turtle/qr.git
cd qr
git checkout "$(git describe --tags --abbrev=0)" # checkout to latest tag, omit for latest commit
meson setup build
meson test -C build
meson install -C build