generateCode($characters); /* font size will be 75% of the image height */ $font_size = $height * 0.75; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 100, 120, 180); /* generate random dots in background */ /* for( $i=0; $i<($width*$height)/12; $i++ ) { imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color); } */ /* generate random lines in background */ for( $i=0; $i<($width*$height)/150; $i++ ) { imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color); } $x = 4; $y = 5; if(function_exists('imagettfbbox') == true) { imagettfbbox($font_size, 0, $font, $code); $textbox = imagettfbbox($font_size, 0, $font, $code); $x = ($width - $textbox[4])/2; $y = ($height - $textbox[5])/2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $font, $code); } else { imagestring($image, $font_fallback, $x, $y, $code, $text_color); } header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); $_SESSION['security_code'] = $code; } } $width = 90; $height = 30; $characters = 6; $font = $APP_CONFIG['base_path'].'/resources/fonts/monofont.ttf'; $font_fallback = imageloadfont($APP_CONFIG['base_path'].'/resources/fonts/captchafont.gdf'); $captcha = new CaptchaSecurityImages($width,$height,$characters,$font); ?>