PHP
Class VeriFyimg {
public $ fontsize = 15; // Define font size
public $ length = 4; // Define string length
public $ width = 70; // Define the width of the picture width
public $height = 30; //Define the image height public $im = null; //Generate an image with a specified width and height public $font = 'C:/Windows/Fonts/Arial.TTF';
public $strNum = ""; public function Build() { $strings = Array ('1', '2','3', '4', '5', '6', '7' , 'a', 'b', 'c', 'd', 'e', 'f', 'h', 'i', 'j', 'k', 'm', 'n', ' p', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y' );// $strNum = ""; $count = count ( $strings ); for($i = 1; $i <= $this->length; $i ++) { //Loop through random characters to generate a string $strNum .= $ strings [rand ( 0, $count - 1 )]; } session_start (); $_SESSION ["verifycode"] = $strNum; $this->im = imagecreate ( $this-> ;width, $this->height ); $backgroundcolor = imagecolorallocate ( $this->im, 255, 255, 255 ); //Generate background color $frameColor = imageColorAllocate ( $this->im , 0, 255, 0 ); for($i = 0; $i < $this->length; $i ++) { $charY = ($this->height + 9) / 2 + rand ( - 1, 1 ); //Define the Y coordinate of the character $charX = $i * 15 + 8; //Define the X coordinate of the character // $text_color = imagecolorallocate($this->im, 255, 0, 0); ), mt_rand ( 50, 200 ) ); $angle = rand ( - 20, 20 ); //Generate character angle //Write characters imagettftext ( $this->im, $this->fontSize, $angle, $charX, $charY, $text_color, $this->font, $strNum [$i] ); } for($i = 0; $i <= 5; $i ++) { //Loop to draw background lines
$linecolor = imagecolorallocate ( $this->im, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) ); $linex = mt_rand ( 1, $this->width - 1 ); $liney = mt_rand ( 1, $this->height - 1 ); imageline ( $this->im, $linex, $liney, $linex + mt_rand ( 0, 4 ) - 2, $liney + mt_rand (0, 4) - 2, $linecolor ); } for($i = 0; $i <= 32; $i ++) { //Loop to draw background points, Generate pitting effect $pointcolor = imagecolorallocate ( $this->im, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) ); imagesetpixel ( $this->im , mt_rand ( 1, $this->width - 1 ), mt_rand ( 1, $this->height - 1 ), $pointcolor ); } imagerectangle ( $this->im, 0, 0 , $this->width - 1, $this->height - 1, $frameColor ); //Draw a border ob_clean (); header ( 'Content-type:image/png' ); imagepng ( $this->im ); imagedestroy ( $this->im ); }}$img = new VerifyImg ();$img->Build ();
?>