example3.c 801 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <stdio.h>
  2. #include <libcaptcha.h>
  3. /*
  4. * Automatically randomize position of glyphs in the array
  5. * by x and then y axis
  6. */
  7. int main() {
  8. char * str = "letsjump";
  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. /*
  19. * Glyph position randomization for both x and y axis
  20. */
  21. lc_randomize_arr_x(arr, 30);
  22. lc_randomize_arr_y(arr, 40);
  23. if (!arr) {
  24. perror("lc_str_to_arr()");
  25. return 1;
  26. }
  27. bmp = lc_arr_to_bmp(arr);
  28. if (!bmp) {
  29. perror("lc_arr_to_bmp()");
  30. return 1;
  31. }
  32. lc_save_png("./example3.png", bmp);
  33. lc_free(arr);
  34. lc_free(bmp);
  35. lc_free(font);
  36. return 0;
  37. }