Page 1 of 1
PHP Drawing. Please Help
Posted: Tue May 30, 2006 10:22 pm
by tecktalkcm0391
Can anyone tell me how the code to make PHP draw random lines on a PHP created image?
This is for a security code (captcah).
Posted: Tue May 30, 2006 10:26 pm
by hawleyjr
why write your own? Google CAPTCHA.
Posted: Tue May 30, 2006 11:01 pm
by tecktalkcm0391
I already have one, I just want to make it draw a few lines randomly on the security code image.
Can anyone help?
Posted: Wed May 31, 2006 12:44 am
by Flamie
yes:
Code: Select all
imageline($image, $startx, $starty, $endx, $endy, $color);
and if you want a random line:
Code: Select all
//create your image
$image = imagecreatefrompng($path); or imagecreatefrombmp($path) or imagecreatefromjpeg($path);
//get your random data
$width = imagesx($image);
$height = imagesy($image);
$startx = rand(0,$width-1);
$starty = rand(0,$height-1);
$endx = rand(0,$width-1);
$endy = rand(0, $height-1);
//if you want black color:
$color = imagecolorallocate($image, 0, 0, 0);
//draw the random line
imageline($image, $startx, $starty, $endx, $endy, $color);
//output the image
imagepng($image); or imagebmp($image); or imagejpeg($image);
//free memory
imagedestroy($image);
Posted: Wed May 31, 2006 2:58 am
by JayBird
These posts dont really belong in the volunteer forum