diff options
-rw-r--r-- | Makefile | 11 | ||||
-rw-r--r-- | captcha.c | 51 | ||||
-rw-r--r-- | captcha.h | 17 | ||||
-rw-r--r-- | code.png | bin | 0 -> 5948 bytes |
4 files changed, 79 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7e71228 --- /dev/null +++ b/Makefile | |||
@@ -0,0 +1,11 @@ | |||
1 | all: | ||
2 | $(CC) -Wall -g -lgd -o captcha -Wl,-rpath=libs/ -L../ -l:libfile_reader.so captcha.c | ||
3 | $(CC) -Wall -g -shared -fPIC -lgd -L../ -l:libfile_reader.so -o captcha.so captcha.c | ||
4 | #$(CC) -Wall -g -lgd -o captcha ../file_reader/file_reader.a captcha.c | ||
5 | |||
6 | libs: | ||
7 | #$(CC) -Wall -g -shared -fPIC -lgd -Wl,-rpath=../file/reader/ -L../file/reader/ -l:file_reader.so -o captcha.so captcha.c | ||
8 | #$(CC) -Wall -g -lgd -Wl,-rpath=../file/reader/ -L../file/reader/ -o captcha ../file/reader/file_reader.a captcha.c | ||
9 | |||
10 | strip: | ||
11 | strip -s *.so | ||
diff --git a/captcha.c b/captcha.c new file mode 100644 index 0000000..18f7d99 --- /dev/null +++ b/captcha.c | |||
@@ -0,0 +1,51 @@ | |||
1 | #include "captcha.h" | ||
2 | |||
3 | int captcha_print(char* text) | ||
4 | { | ||
5 | File* file = file_open("code.png"); | ||
6 | |||
7 | gdImagePtr im = gdImageCreateFromPngPtr(file->size, file->data); | ||
8 | gdImageColorTransparent(im, gdImageColorAllocate(im, 255, 255, 255)); | ||
9 | |||
10 | char text_width = strlen(text); | ||
11 | float letter_width = ((float) gdImageSX(im) / 26.00); | ||
12 | |||
13 | int image_width = letter_width * text_width; | ||
14 | int image_height = gdImageSY(im); | ||
15 | |||
16 | gdImagePtr image = gdImageCreateTrueColor(image_width, image_height); | ||
17 | gdImageColorTransparent(image, gdImageColorAllocate(image, 0, 0, 0)); | ||
18 | |||
19 | srand(time(NULL) * (*text)); | ||
20 | int i; | ||
21 | for(i=0; i<=10; i++) | ||
22 | { | ||
23 | int x1 = ((double) rand() / RAND_MAX) * image_width; | ||
24 | int y1 = ((double) rand() / RAND_MAX) * image_height; | ||
25 | 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); | ||
26 | } | ||
27 | |||
28 | int pos; | ||
29 | for(pos=0; text[pos]!='\0'; pos++) | ||
30 | { | ||
31 | //printf("[pos:%d] %d\n", pos, (text[pos] - 65) ); | ||
32 | gdImageCopyMerge(image, im, | ||
33 | letter_width * pos, 0, | ||
34 | ((text[pos] - 65) * letter_width), 0, | ||
35 | letter_width, gdImageSY(image), 50); | ||
36 | } | ||
37 | |||
38 | puts("content-type: image/jpeg\n"); | ||
39 | gdImageJpeg(image, stdout, 80); | ||
40 | |||
41 | gdImageDestroy(image); | ||
42 | gdImageDestroy(im); | ||
43 | |||
44 | file_close(file); | ||
45 | return EXIT_SUCCESS; | ||
46 | } | ||
47 | |||
48 | int main() | ||
49 | { | ||
50 | return captcha_print("HALLELUJA"); | ||
51 | } | ||
diff --git a/captcha.h b/captcha.h new file mode 100644 index 0000000..2aa6475 --- /dev/null +++ b/captcha.h | |||
@@ -0,0 +1,17 @@ | |||
1 | #ifndef CAPTCHA_H | ||
2 | #define CAPTCHA_H | ||
3 | |||
4 | #include <stdio.h> | ||
5 | #include <stdlib.h> | ||
6 | #include <err.h> | ||
7 | |||
8 | #include <time.h> // used for rand() | ||
9 | #include <string.h> | ||
10 | |||
11 | #include "gd.h" | ||
12 | #include "../file_reader/file_reader.h" | ||
13 | |||
14 | |||
15 | int captcha_print(char* text); | ||
16 | |||
17 | #endif | ||
diff --git a/code.png b/code.png new file mode 100644 index 0000000..df904ae --- /dev/null +++ b/code.png | |||
Binary files differ | |||