example1.c 668 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <stdio.h>
  2. #include <libcaptcha.h>
  3. /*
  4. * This example simply prints glyphs into
  5. * png file. Here is nothing but basics
  6. */
  7. int main() {
  8. char * str = "😒Hi!";
  9. char * fontfile = "../ttf/dejavu.ttf";
  10. lc_fontBuffer *font = lc_create_font(fontfile);
  11. lc_arrGlyph *arr;
  12. lc_bmp * bmp;
  13. if (!font) {
  14. perror("lc_create_font()");
  15. return 1;
  16. }
  17. arr = lc_str_to_arr(font, str, 38, 0);
  18. if (!arr) {
  19. perror("lc_str_to_arr()");
  20. return 1;
  21. }
  22. bmp = lc_arr_to_bmp(arr);
  23. if (!bmp) {
  24. perror("lc_arr_to_bmp()");
  25. return 1;
  26. }
  27. lc_save_png("./example1.png", bmp);
  28. lc_free(arr);
  29. lc_free(bmp);
  30. lc_free(font);
  31. return 0;
  32. }