#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"); }