fix image text master
authorAlan <alan@roojs.com>
Mon, 22 Apr 2024 03:56:21 +0000 (11:56 +0800)
committerAlan <alan@roojs.com>
Mon, 22 Apr 2024 03:56:21 +0000 (11:56 +0800)
Image/Text.php
Text/CAPTCHA/Driver/Image.php

index 223775d..0598020 100644 (file)
@@ -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;
         }
index 3b3c94e..6949afb 100644 (file)
@@ -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();