示例#1
0
{
    /* Display Captcha */
    public function display($width, $height, $text)
    {
        /* Create Image */
        $image = imagecreate($width, $height);
        /* Set Background */
        $bg = imagecolorallocate($image, 255, 255, 255);
        /* Set Text Color */
        $color = imagecolorallocate($image, 0, 0, 0);
        /* Patch together Image */
        /* First character */
        $r = rand(-25, 25);
        imagettftext($image, 26, $r, 10, 33, $color, "fonts/arial.ttf", substr($text, 0, 1));
        /* Each character after that */
        for ($i = 0; $i <= strlen($text); $i++) {
            $part = substr($text, $i + 1, 1);
            $r = rand(-25, 25);
            $x = 36 + 26 * $i;
            imagettftext($image, 26, $r, $x, 37, $color, "fonts/arial.ttf", $part);
        }
        /* Output the image */
        header('Content-type: image/png');
        imagepng($image);
        imagedestroy($image);
    }
}
$captcha = new captcha();
session_start();
echo $captcha->display("170", "50", $_SESSION['captcha']);
示例#2
0
//////////////////////////////////////////////////////////////////////////////////////////////////
// make image
/**
 * the time() at the end of the address is just to keep the image from being cached
 * <img id="captcha_img" src="./captcha/cf.captcha.php?img=<?=time();?>" />
 *
 */
if (isset($_GET['img'])) {
    $capt = new captcha();
    if (isset($_GET['bg'])) {
        //$capt->transparent_bg(false);
        //$capt->bg_color($_GET['bg']);
        $capt->colorshad = 'd';
    }
    $capt->add_wave();
    $capt->display();
    exit;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// captcha Class
class captcha
{
    private $UserString;
    /**
     * The width of the captcha image
     * @var integer
     */
    private $width = 120;
    /**
     * The height of the captcha image
     * @var unknown_type
示例#3
0
 /**
  * @description Displaying/saving captcha
  * @repeat 20
  */
 function display()
 {
     captcha::display($this->captchaid, $this->getTempFile('png'));
 }