From a66a946b86ff701e30b796c73367c791d21f9209 Mon Sep 17 00:00:00 2001 From: Max Christian Pohle Date: Mon, 12 Oct 2015 04:15:25 +0200 Subject: version depends on gd and creates a traditional captcha --- captcha.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 captcha.c (limited to 'captcha.c') diff --git a/captcha.c b/captcha.c new file mode 100644 index 0000000..18f7d99 --- /dev/null +++ b/captcha.c @@ -0,0 +1,51 @@ +#include "captcha.h" + +int captcha_print(char* text) +{ + File* file = file_open("code.png"); + + gdImagePtr im = gdImageCreateFromPngPtr(file->size, file->data); + gdImageColorTransparent(im, gdImageColorAllocate(im, 255, 255, 255)); + + char text_width = strlen(text); + float letter_width = ((float) gdImageSX(im) / 26.00); + + int image_width = letter_width * text_width; + int image_height = gdImageSY(im); + + gdImagePtr image = gdImageCreateTrueColor(image_width, image_height); + gdImageColorTransparent(image, gdImageColorAllocate(image, 0, 0, 0)); + + srand(time(NULL) * (*text)); + int i; + for(i=0; i<=10; i++) + { + int x1 = ((double) rand() / RAND_MAX) * image_width; + int y1 = ((double) rand() / RAND_MAX) * image_height; + gdImageFilledArc(image, x1, y1, x1 + 10, y1 + 10, ((double) rand() / RAND_MAX) * 360, ((double) rand() / RAND_MAX) * 360, gdImageColorAllocate(image, 100 + (rand() * 155), 150 + (rand() * 105), 150 + (rand() * 105)), gdEdged); + } + + int pos; + for(pos=0; text[pos]!='\0'; pos++) + { + //printf("[pos:%d] %d\n", pos, (text[pos] - 65) ); + gdImageCopyMerge(image, im, + letter_width * pos, 0, + ((text[pos] - 65) * letter_width), 0, + letter_width, gdImageSY(image), 50); + } + + puts("content-type: image/jpeg\n"); + gdImageJpeg(image, stdout, 80); + + gdImageDestroy(image); + gdImageDestroy(im); + + file_close(file); + return EXIT_SUCCESS; +} + +int main() +{ + return captcha_print("HALLELUJA"); +} -- cgit v1.2.3