_type, $name); $this->_captchaImage = 'thumbnail.php?option=captcha&name=' . $this->_name; $this->addValidator('Captcha'); if ($length !== null) { $this->_length = intval($length); } if ($width !== null) { $this->_width = intval($width); } if ($height !== null) { $this->_height = intval($height); } $this->_font = __DIR__ . '/../../../../fonts/Candal.ttf'; } /** * * create the captcha code and save it in a session variable * * @return string */ public function setCode() { srand(); $this->_code = substr(md5(rand(2, 9999999999)), 0, $this->_length); $session = new PPS_Session(); $session->set($this->_name, $this->_code); return $this->_code; } /** * * get the captcha code * * @return string */ public function getCode() { if (!$this->_code) { $this->setCode(); } return $this->_code; } /** * * create the captcha image */ public function createImage() { $this->_image = imagecreate($this->_width, $this->_height); $white = imagecolorallocate($this->_image, 255, 255, 255); $grey = imagecolorallocate($this->_image, 180, 180, 180); $black = imagecolorallocate($this->_image, 0, 0, 0); $code = $this->getCode(); $height = $this->_height - (($this->_height - $this->_fontSize) / 2); // Add some shadow to the text imagettftext($this->_image, $this->_fontSize, 0, 41, ($height - 1), $grey, $this->_font, $this->_code); // Add the text imagettftext($this->_image, $this->_fontSize, 0, 40, $height, $black, $this->_font, $this->_code); srand(); // add noise (pixels) for ($i = 1; $i <= $this->_pixels; $i++) { imagesetpixel($this->_image, rand(0, $this->_width), rand(0, $this->_height), $black); } // add noise (circles) for ($i = 1; $i <= $this->_circles; $i++) { imageellipse($this->_image, rand(0, $this->_width), rand(0, $this->_height), rand(60, 150), rand(60, 150), $black); } header("Content-Type: image/png"); imagepng($this->_image); imagedestroy($this->_image); } public function render() { return 'renderAttributes() . $this->_endTag; } }