1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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 - 2);
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; pos<text_width-1; 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");
}
|