How to manipulate images using php

Asked By 0 points N/A Posted on -
qa-featured

Hello, im currently trying to develop a new captcha system for websites using php, html and javascript and i would like to know how i can manipulate images using php especially ones involving distortion, rotation, resizing or scaling, color filtering and image cropping. Please help as soon as you can, i would really be grateful for quick response

SHARE
Answered By 0 points N/A #164283

How to manipulate images using php

qa-featured

There are basically 3 types of captcha first one and widely used is image captcha , second is mathematical captcha and last one is vice captcha.

First Generate captcha image

<?php

session_start();

$code=rand(1000,9999);

$_SESSION["code"]=$code;

$im = imagecreatetruecolor(50, 24);

$bg = imagecolorallocate($im, 22, 86, 165); //background color blue

$fg = imagecolorallocate($im, 255, 255, 255);//text color white

imagefill($im, 0, 0, $bg);

imagestring($im, 5, 5, 5,  $code, $fg);

header("Cache-Control: no-cache, must-revalidate");

header('Content-type: image/png');

imagepng($im);

imagedestroy($im);

?>

 

Put captcha image in html form

 

<html>

<head>

<title>Test Form</title>

</head>

<body>

<form action="validate.php" method="post">

Enter Image Text

<input name="captcha" type="text">

<img src="captcha.php" /><br>

<input name="submit" type="submit" value="Submit">

</form>

</body>

</html>

 

Now validate Captcha response

<?php

session_start();

if(isset($_POST["captcha"])&&$_POST["captcha"]!=""&&$_SESSION["code"]==$_POST["captcha"])

{

echo "Correct Code Entered";

//Do you stuff

}

else

{

die("Wrong Code Entered");

}

?>

 

Login/Register to Answer

Related Questions