From 79946b9682c99c0b685003a7b5931e8088576b37 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 26 Feb 2014 15:09:58 +0100 Subject: Add a note about the library to the documentation --- README.md | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/README.md b/README.md index ae794d5..19668d2 100644 --- a/README.md +++ b/README.md @@ -65,3 +65,56 @@ Runtime options can be given with request method GET. These are available: * `border`: width of the border * `level`: error correction level +Library +------- + +This now uses a shared library the can be used to create CGI executables for +your custom needs. This is minimal sample source code: + + #include + + int main(int argc, char **argv) { + struct bitmap_t * bitmap; + struct png_t * png; + struct cqrconf_t cqrconf; + + cqrconf.scale = 2; + cqrconf.border = 1; + cqrconf.level = 0; + cqrconf.overwrite = 1; + + /* encode the QR-Code */ + if ((bitmap = encode_qrcode("https://github.com/eworm-de/cqrlogo", cqrconf)) == NULL) { + fprintf(stderr, "Could not generate QR-Code.\n"); + return EXIT_FAILURE; + } + + /* generate PNG data */ + if ((png = generate_png(bitmap, CQR_COMMENT|CQR_VERSION|CQR_LIBVERSION, "https://github.com/eworm-de/cqrlogo")) == NULL) { + fprintf(stderr, "Failed to generate PNG.\n"); + return EXIT_FAILURE; + } + + /* print HTTP header */ + printf("Content-Type: image/png\n\n"); + + /* write PNG data to stdout */ + if (fwrite(png->buffer, png->size, 1, stdout) != 1) { + fprintf(stderr, "Failed writing PNG data to stdout.\n"); + return EXIT_FAILURE; + } + + /* free memory we no longer need */ + bitmap_free(bitmap); + if (png->size > 0) + free(png->buffer); + free(png); + + return EXIT_SUCCESS; + } + +Save this code to `cqrlogo.c` and run: + +> gcc -lcqrlogo -o cqrlogo.cgi cqrlogo.c + +This will result in a CGI executable `cqrlogo.cgi`. -- cgit v1.2.3-54-g00ecf