gpt4 book ai didi

c - C 语言的 GD 验证码生成器

转载 作者:行者123 更新时间:2023-11-30 18:43:41 24 4
gpt4 key购买 nike

我正在用 C 语言为我的网站编写一个 fastcgi 应用程序。

如何使用GD生成验证码图像?

我在谷歌上徒劳地搜索了一些东西(搜索仍在进行中),但如果有人能给我有关该过程的基本概念,那就太好了。

对于随机数,我将使用纳秒作为种子(或使用它本身)。

提前致谢。

最佳答案

查看 void gdImageStringUp(gdImagePtr im, gdFontPtr font, int x, int y, unsigned char *s, int color) (FUNCTION) 代码示例(您几乎可以复制粘贴它) )..

  #include "gd.h"
#include "gdfontl.h"
#include <string.h>

/*... inside a function ...*/
gdImagePtr im;
int black;
int white;
/* String to draw. */
char *s = "Hello.";
im = gdImageCreate(100, 100);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Draw a centered string going upwards. Axes are reversed,
and Y axis is decreasing as the string is drawn. */
gdImageStringUp(im, gdFontGetLarge(),
im->w / 2 - gdFontGetLarge()->h / 2,
im->h / 2 + (strlen(s) * gdFontGetLarge()->w / 2), s, white);
/* ... Do something with the image, such as
saving it to a file... */
/* Destroy it */
gdImageDestroy(im);

http://www.libgd.org/Font

噪声是通过随机像素/线条/等完成的,这很简单:

  /*... inside a function ...*/
gdImagePtr im;
int black;
int white;
im = gdImageCreate(100, 100);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Set a pixel near the center. */
gdImageSetPixel(im, 50, 50, white);
/* ... Do something with the image, such as
saving it to a file... */
/* Destroy it */
gdImageDestroy(im);

http://www.libgd.org/Drawing

LibGD 在他们的网站上有无数的例子。

关于c - C 语言的 GD 验证码生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3446664/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com