在图像中为验证码创建随机曲线

编程入门 行业动态 更新时间:2024-10-23 18:34:15
本文介绍了在图像中为验证码创建随机曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想创建一个脚本,以创建类似于某些流行网站所使用的验证码的验证码图像,如下图所示。 我已经创建了生成验证码的脚本,但我想使其类似于以下内容

I want to create an script for creating captcha images similar to the captcha used by some popular websites like in the image below. I have created the script which generates captcha but I want to make it somewhat like below

我想在图片中添加这些随机线,但我无法弄清楚该如何处理实现它,请建议如何在PHP。或我可以参考的任何类似开源项目中实现它。

And I want to add those random lines in the image but I cant figure our how can I achieve it,Please suggest how to do it in PHP.or any similar open-source project I can reference to.

推荐答案

下面的代码为您提供了执行所需操作的起点。请注意,这提供了比您发布的示例图像更简单的输出。

The below code gives you a starting point to do what you want. Note that this gives a much simpler output than the example images you posted.

这里生成了4张图像:

您真正感兴趣的唯一部分是 for 循环,但这是一个完全正常的示例:

The only part you are really are interested in is the for loop, but this is a fully working example:

$im = imagecreatetruecolor(150, 75); $bg = imagecolorallocate($im, 220, 220, 220); $white = imagecolorallocate($im, 255, 255, 255); $black = imagecolorallocate($im, 0, 0, 0); // set background colour. imagefilledrectangle($im, 0, 0, 150, 75, $bg); // output text. imagettftext($im, 35, 0, 10, 55, $black, 'arial.ttf', 'ABCD'); for ($i = 0; $i < 50; $i++) { //imagefilledrectangle($im, $i + $i2, 5, $i + $i3, 70, $black); imagesetthickness($im, rand(1, 5)); imagearc( $im, rand(1, 300), // x-coordinate of the center. rand(1, 300), // y-coordinate of the center. rand(1, 300), // The arc width. rand(1, 300), // The arc height. rand(1, 300), // The arc start angle, in degrees. rand(1, 300), // The arc end angle, in degrees. (rand(0, 1) ? $black : $white) // A color identifier. ); } header('Content-type: image/png'); imagepng($im); imagedestroy($im);

调整 for 循环的限制,然后 rand()调用中的最大值将影响弧的密度。

Tweaking the limit of the for loop and the max value in the rand() calls will affect the 'density' of the arcs.

更多推荐

在图像中为验证码创建随机曲线

本文发布于:2023-11-01 02:22:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547978.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:验证码   中为   曲线   图像

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!