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

调用代码:

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

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

thinkphp3.1.3验证码优化

优化

找到源码(ThinkPHP\Extend\Library\ORG\Util\Image.class.php的buildImageVerify方法内):

thinkphp3.1.3验证码优化

修改如下:

$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);
}

优化后效果:

thinkphp3.1.3验证码优化

相关文章:

  • 2022-12-23
  • 2022-01-17
  • 2021-04-05
  • 2021-08-13
  • 2021-06-25
  • 2021-10-01
  • 2022-12-23
  • 2021-06-07
猜你喜欢
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2021-04-29
相关资源
相似解决方案