/ Published in: PHP
Expand |
Embed | Plain Text
<?php class CaptchaSecurityImages { var $font = './monofont.ttf'; function generateCode($characters) { /* list all possible characters, similar looking characters and vowels have been removed */ //$possible = '23456789bcdfghjkmnpqrstvwxyz'; $possible = '1234567890'; // 1st try... $i = 0; while ($i < $characters) { $i++; } return $code; } function CaptchaSecurityImages($width='100',$height='50',$characters='6') { $code = $this->generateCode($characters); /* font size will be 75% of the image height */ $font_size = $height * 0.60; /* set the colours */ $background_color = imagecolorallocate($image, 180, 110, 63); $text_color = imagecolorallocate($image, 120, 50, 10); $noise_color = imagecolorallocate($image, 255, 150, 102); /* generate random dots in background */ for( $i=0; $i<($width*$height)/3; $i++ ) { } /* generate random lines in background */ for( $i=0; $i<($width*$height)/150; $i++ ) { } /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $this->font, $code); $x = ($width - $textbox[4])/2; $y = ($height - $textbox[5])/2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code); /* output captcha image to browser */ imagejpeg($image); imagedestroy($image); $_SESSION['security_code'] = $code; } } $characters = isset($_GET['characters']) ? $_GET['characters'] : '3'; //number of characters to show $captcha = new CaptchaSecurityImages($width,$height,$characters); ?>
You need to login to post a comment.
