我找到了一些自定义验证码代码,它运行良好,但我无法调整它的大小。我的目标是让它高 28px,但每当我将"高度"变量更改为 28 时,它就会扭曲,它保持相同的大小,只是文本变得更大且不可读。我不知道还有什么要改变的,你能帮我吗?
session_start();
$text = rand(100,999).'-'.rand(100,999);
$_SESSION["vercode"] = $text;
$height = 80;
$width = 130;
$image_p = imagecreate($width, $height);
$height = 1;
$width = 5;
$noiseColor = imagecolorallocate($image_p, rand(50,255), rand(50,250), rand(50,255));// Sets the color of the interference
for( $i = 0; $i < ($width * $height)/150; $i++ )
{
imageline($image_p, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noiseColor);
}
$black = imagecolorallocate($image_p, 255, 255, 255);
$white = imagecolorallocate($image_p, 0, 0, 0);
$font_size = 14;
imagestring($image_p, $font_size, rand(20,32), rand(10,40), $text, $white);
imagejpeg($image_p, null, 80);
你来:)
只需将$height = 80;
更改为$height = 28;
当您想放置文本时,请更改:
imagestring($image_p, $font_size, rand(20,32), rand(10,40), $text, $white);
对此
imagestring($image_p, $font_size, rand(20,32), rand(2,10), $text, $white);