From: Alan Date: Mon, 22 Apr 2024 03:56:21 +0000 (+0800) Subject: fix image text X-Git-Url: http://git.roojs.org/?p=pear;a=commitdiff_plain;h=HEAD fix image text --- diff --git a/Image/Text.php b/Image/Text.php index 223775dd..0598020b 100644 --- a/Image/Text.php +++ b/Image/Text.php @@ -369,12 +369,14 @@ class Image_Text { * @see Image_Text::set(), Image_Text::construct(), Image_Text::init() */ - function Image_Text($text, $options = null) + function __construct($text, $options = null) { - $this->set('text', $text); + $this->set('text', $text); + if (!empty($options)) { - $this->options = array_merge($this->options, $options); - } + $this->options = array_merge($this->options, $options); + } + } /** @@ -564,12 +566,13 @@ class Image_Text { // todo: with some versions of the GD-library it's also possible to leave font_path empty, add strip ".ttf" from // the fontname; the fontfile will then be automatically searched for in library-defined directories // however this does not yet work if at this point we check for the existance of the fontfile + $font_file = rtrim($this->options['font_path'], '/\\'); $font_file.= (OS_WINDOWS) ? '\\' : '/'; $font_file.= $this->options['font_file']; $font_file = realpath($font_file); if (empty($font_file) || !is_file($font_file) || !is_readable($font_file)) { - return PEAR::staticRaiseError('Fontfile not found or not readable.'); + return PEAR::staticRaiseError('Fontfile not found or not readable: ' . $font_file); } else { $this->_font = $font_file; } diff --git a/Text/CAPTCHA/Driver/Image.php b/Text/CAPTCHA/Driver/Image.php index 3b3c94eb..6949afb7 100644 --- a/Text/CAPTCHA/Driver/Image.php +++ b/Text/CAPTCHA/Driver/Image.php @@ -102,6 +102,7 @@ class Text_CAPTCHA_Driver_Image extends Text_CAPTCHA */ function init($options = array()) { + if (!is_array($options)) { // Compatibility mode ... in future versions, these two // lines of code will be used: @@ -148,8 +149,10 @@ class Text_CAPTCHA_Driver_Image extends Text_CAPTCHA if (isset($options['imageOptions']) && is_array($options['imageOptions']) && count($options['imageOptions']) > 0) { $this->_imageOptions = array_merge($this->_imageOptions, $options['imageOptions']); } + return true; } + } /** @@ -209,11 +212,13 @@ class Text_CAPTCHA_Driver_Image extends Text_CAPTCHA $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::staticRaiseError( sprintf('Error initializing Image_Text (%s)', $e->getMessage())); @@ -305,15 +310,14 @@ class Text_CAPTCHA_Driver_Image extends Text_CAPTCHA if (PEAR::isError($retval)) { 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; } } @@ -333,7 +337,7 @@ class Text_CAPTCHA_Driver_Image extends Text_CAPTCHA return PEAR::raiseError($retval->getMessage()); } - if (is_resource($this->_im)) { + if (is_object($this->_im)) { ob_start(); imagejpeg($this->_im); $data = ob_get_contents(); @@ -360,7 +364,7 @@ class Text_CAPTCHA_Driver_Image extends Text_CAPTCHA return PEAR::raiseError($retval->getMessage()); } - if (is_resource($this->_im)) { + if (is_object($this->_im)) { ob_start(); imagegif($this->_im); $data = ob_get_contents();