<?php
/**
- *
* Require Image_Text class for generating the text.
- *
*/
require_once 'Text/CAPTCHA.php';
require_once 'Image/Text.php';
* Text_CAPTCHA_Driver_Image - Text_CAPTCHA driver graphical CAPTCHAs
*
* Class to create a graphical Turing test
- *
*
+ * @author Christian Wenz <wenz@php.net>
* @license BSD License
- * @author Christian Wenz <wenz@php.net>
* @todo refine the obfuscation algorithm :-)
* @todo consider removing Image_Text dependency
*/
'font_file' => 'COUR.TTF',
'text_color' => '#000000',
'lines_color' => '#CACACA',
- 'background_color' => '#555555');
+ 'background_color' => '#555555',
+ 'antialias' => false);
/**
* Whether the immage resource has been created
*
* Initializes the new Text_CAPTCHA_Driver_Image object and creates a GD image
*
- * @param array $options CAPTCHA options
+ * @param array $options CAPTCHA options
+ *
* @access public
- * @return mixed true upon success, PEAR error otherwise
+ * @return mixed true upon success, PEAR error otherwise
*/
function init($options = array())
{
+
if (!is_array($options)) {
// Compatibility mode ... in future versions, these two
// lines of code will be used:
}
if (is_array($options)) {
if (isset($options['width']) && is_int($options['width'])) {
- $this->_width = $options['width'];
+ $this->_width = $options['width'];
} else {
- $this->_width = 200;
+ $this->_width = 200;
}
if (isset($options['height']) && is_int($options['height'])) {
- $this->_height = $options['height'];
+ $this->_height = $options['height'];
} else {
- $this->_height = 80;
+ $this->_height = 80;
}
if (!isset($options['phrase']) || empty($options['phrase'])) {
$phraseoptions = (isset($options['phraseOptions']) && is_array($options['phraseOptions'])) ? $options['phraseOptions'] : array();
if (isset($options['imageOptions']) && is_array($options['imageOptions']) && count($options['imageOptions']) > 0) {
$this->_imageOptions = array_merge($this->_imageOptions, $options['imageOptions']);
}
+
return true;
}
+
}
/**
*
* This method creates a random phrase, maximum 8 characters or width / 25, whatever is smaller
*
- * @access private
+ * @param array $options Optionally supply advanced options for the phrase creation
+ *
+ * @access private
+ * @return void
*/
function _createPhrase($options = array())
{
$options['background_color'] = $this->_imageOptions['background_color'];
$options['max_lines'] = 1;
$options['mode'] = 'auto';
- do {
+ do {
$this->_imt = new Image_Text(
$this->_phrase,
$options
);
+
+
if (PEAR::isError($e = $this->_imt->init())) {
- $this->_error = PEAR::raiseError(
- sprintf('Error initializing Image_Text (%s)',
- $e->getMessage()));
+ $this->_error = PEAR::staticRaiseError(
+ sprintf('Error initializing Image_Text (%s)', $e->getMessage()));
return $this->_error;
} else {
$this->_created = true;
$this->_error = PEAR::raiseError('The text provided does not fit in the image dimensions');
return $this->_error;
}
- $this->_imt->render();
+ $this->_imt->render();
$this->_im =& $this->_imt->getImg();
+
+ if (isset($this->_imageOptions['antialias']) && $this->_imageOptions['antialias'] === true && function_exists('imageantialias')) {
+ imageantialias($this->_im, true);
+ }
+
$colors = $this->_imt->_convertString2RGB($this->_imageOptions['lines_color']);
$lines_color = imagecolorallocate($this->_im, $colors['r'], $colors['g'], $colors['b']);
//some obfuscation
{
$retval = $this->_createCAPTCHA();
if (PEAR::isError($retval)) {
- return PEAR::raiseError($retval->getMessage());
+ return PEAR::staticRaiseError($retval->getMessage());
}
if ($this->_output == 'gif' && !function_exists('imagegif')) {
{
$retval = $this->_createCAPTCHA();
if (PEAR::isError($retval)) {
- return PEAR::raiseError($retval->getMessage());
+ return PEAR::staticRaiseError($retval->getMessage());
}
-
- if (is_resource($this->_im)) {
+ if (is_object($this->_im)) {
ob_start();
imagepng($this->_im);
$data = ob_get_contents();
ob_end_clean();
return $data;
} else {
- $this->_error = PEAR::raiseError('Error creating CAPTCHA image (font missing?!)');
+ $this->_error = PEAR::staticRaiseError('Error creating CAPTCHA image (font missing?!)');
return $this->_error;
}
}
return PEAR::raiseError($retval->getMessage());
}
- if (is_resource($this->_im)) {
+ if (is_object($this->_im)) {
ob_start();
imagejpeg($this->_im);
$data = ob_get_contents();
return PEAR::raiseError($retval->getMessage());
}
- if (is_resource($this->_im)) {
+ if (is_object($this->_im)) {
ob_start();
imagegif($this->_im);
$data = ob_get_contents();
/**
* __wakeup method (PHP 5 only)
+ *
+ * @return void
*/
function __wakeup()
{