PHP Drawing. Please Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

PHP Drawing. Please Help

Post 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).
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:1. Select the correct board for your query. Take some time to read the guidelines in the sticky topic.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

why write your own? Google CAPTCHA.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post 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?
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post 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);
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

These posts dont really belong in the volunteer forum
Post Reply