summaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2014-02-26 15:09:58 +0100
committerGravatar Christian Hesse <mail@eworm.de>2014-02-26 15:09:58 +0100
commit79946b9682c99c0b685003a7b5931e8088576b37 (patch)
tree2aa85fd1141c62f12f496650bada0f8fa047dc14 /README.md
parentd0e3b7be5a5f79e52a6469c3480b288213580a02 (diff)
downloadcqrlogo-79946b9682c99c0b685003a7b5931e8088576b37.tar.gz
cqrlogo-79946b9682c99c0b685003a7b5931e8088576b37.tar.zst
Add a note about the library to the documentation
Diffstat (limited to 'README.md')
-rw-r--r--README.md53
1 files changed, 53 insertions, 0 deletions
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 <libcqrlogo.h>
+
+ 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`.