向验证码图像添加额外的噪音?
我从网上得到了这个简单的验证码脚本。我喜欢它,并且我对其进行了编辑以适合我的网站,但想知道是否有人可以对其进行编辑以在验证码本身上添加一些随机行,因为它有点太简单了。
我确实找到了有关如何执行此操作的教程,但它对我不起作用。
这是简单的验证码脚本;我很想修改它,让验证码上出现一些随机行:
$width = 150;
$height = 24;
$length = 5;
$font = 'caviardreams.ttf';
$font_size = 14;
$bg_color = array(245, 245, 245);
$chars = 'ABCDEFGHKMNPQRSTUVWXYZ23456789';
session_start();
//putenv('GDFONTPATH=' . realpath('.'));
$img = imagecreatetruecolor($width, $height);
$bkgr = imagecolorallocate($img, $bg_color[0], $bg_color[1], $bg_color[2]);
imagefilledrectangle($img, 0, 0, $width, $height, $bkgr);
$code = '';
for($i = 0; $i < $length; $i++)
{
$code .= $chr = $chars[mt_rand(0, strlen($chars)-1)];
$r = rand(0, 192);
$g = rand(0, 192);
$b = rand(0, 192);
$color = imagecolorallocate($img, $r, $g, $b);
$rotation = rand(-35, 35);
$x = 5+$i*(4/3*$font_size+2);
$y = rand(4/3*$font_size, $height-(4/3*$font_size)/2);
imagettftext($img, $font_size, $rotation, $x, $y, $color, $font, $chr);
}
$_SESSION['random_txt'] = md5($code);
header("Content-type: image/png");
header("Expires: Mon, 01 Jul 1998 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
imagepng($img);
imagedestroy($img);
I have this simple captcha script from online. I like it, and I edited it to suit my site, but was wondering if someone could edit it to add some random lines on the captcha itself as it is somewhat too simple.
I did find tutorials on how to do it but it was not working for me.
Here is the simple captcha script; I would love to modify it to have some random lines appear on the captcha:
$width = 150;
$height = 24;
$length = 5;
$font = 'caviardreams.ttf';
$font_size = 14;
$bg_color = array(245, 245, 245);
$chars = 'ABCDEFGHKMNPQRSTUVWXYZ23456789';
session_start();
//putenv('GDFONTPATH=' . realpath('.'));
$img = imagecreatetruecolor($width, $height);
$bkgr = imagecolorallocate($img, $bg_color[0], $bg_color[1], $bg_color[2]);
imagefilledrectangle($img, 0, 0, $width, $height, $bkgr);
$code = '';
for($i = 0; $i < $length; $i++)
{
$code .= $chr = $chars[mt_rand(0, strlen($chars)-1)];
$r = rand(0, 192);
$g = rand(0, 192);
$b = rand(0, 192);
$color = imagecolorallocate($img, $r, $g, $b);
$rotation = rand(-35, 35);
$x = 5+$i*(4/3*$font_size+2);
$y = rand(4/3*$font_size, $height-(4/3*$font_size)/2);
imagettftext($img, $font_size, $rotation, $x, $y, $color, $font, $chr);
}
$_SESSION['random_txt'] = md5($code);
header("Content-type: image/png");
header("Expires: Mon, 01 Jul 1998 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
imagepng($img);
imagedestroy($img);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就在:之前
插入:
Right before:
Insert:
鉴于您想坚持使用该脚本,您可以查看
这两个项目似乎都符合您想做的事情。
Given that you want to stick with that script, you can look at this scripts source and figure out how the do the design patterns. Sorry if this is not the answer you are looking for. The sections I would highlight for you to concentrate on would be:
Both of those items seem to be right up your alley of what you are wanting to do.