thinkphp3.1.3验证码优化

现状

thinkphp3.1.3版本中的验证码字符分布不均匀,在自定义宽高时很明显。

调用代码:

Image::buildImageVerify(6, 5, 'png', 150, 50);

生成的验证码效果如下图所示:

优化

找到源码(ThinkPHPExtendLibraryORGUtilImage.class.php的buildImageVerify方法内):

修改如下:

$w = floor($width / $length);
for ($i = 0; $i < $length; $i++) {
    imagestring($im, 5, mt_rand($i * $w, $i * $w + $w - 15), mt_rand(5, $height - 15), $randval{$i}, $stringColor);
}

优化后效果:

原文地址:https://www.cnblogs.com/lurenjiashuo/p/thinkphp-verify.html