NakedCat
NakedCat

Reputation: 860

PHP - Custom captcha is not resizing

I've found some custom captcha code, and it works perfectly, but I can't resize it. My goal is to make it 28px high, but whenever I change the "height" variable to 28 it simply distorts, it stays the same size, only text gets bigger and unreadable. I don't know what else to change, could you please help me with it?

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

Upvotes: 0

Views: 56

Answers (1)

vaso123
vaso123

Reputation: 12391

Here you go :)

Simple change the $height = 80; to $height = 28;

And when you want to put the text, change:

imagestring($image_p, $font_size, rand(20,32), rand(10,40), $text, $white);

to this

imagestring($image_p, $font_size, rand(20,32), rand(2,10), $text, $white);

Upvotes: 1

Related Questions