PHP - 自定义验证码没有调整大小

时间:2014-12-08 12:15:23

标签: php html

我找到了一些自定义验证码,它运行得很完美,但我无法调整它的大小。我的目标是使其高达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); 

1 个答案:

答案 0 :(得分:1)

你走了:))

简单地将$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);