Posted by: ranacse05 on: April 11, 2008
When ever we try to get register ourselves in any web app we have to pass the image validation.Its for the security.This can be done in 2 ways
If we follow the first one the we have to have a database where we’ll store the image.And we have to generate lots of image manually and stored there.Sounds bad to me
.
I was just working on a new project.There i have to use an image validation.So i wrote a library which will generate the image dynamically,so i dont have to worry about generate a lots of image and store them on database.Here is the code
<?php
function security_image($rand) {
$width = 100;
$height = 25;
$image = imagecreate($width, $height);
$bgColor = imagecolorallocate ($image, 255, 255, 255);
$textColor = imagecolorallocate ($image, 255, 0, 0);
// Add Random noise
for ($i = 0; $i < 10; $i++) {
$rx1 = rand(0,$width);
$rx2 = rand(0,$width);
$ry1 = rand(0,$height);
$ry2 = rand(0,$height);
$rcVal = rand(0,255);
$rc1 = imagecolorallocate($image,
rand(0,255),
rand(0,255),
rand(100,255));
imageline ($image, $rx1, $ry1, $rx2, $ry2, $rc1);
}
imagestring($image, 5, 30, 10, $rand, $textColor);
@header(‘Content-type: image/png’);
imagepng($image,”s.png”);
imagedestroy($image);
}
?>
Now call the function
$new = //your string u wanna show as image
security_image($new);
Then use img tag to view the s.png file where u want.
good work…
cool ….. sounds really gr8 ….good job!
April 11, 2008 at 11:39 pm
Nice work. I’m also trying this with the help of Net. thnx for faster help.