Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.0.2

Doc Bug #11960 The 'background_color' key in the $_imageOptions array is incorrect data type
Submitted: 2007-09-02 00:54 UTC
From: joepublick Assigned: wenz
Status: Closed Package: Text_CAPTCHA (version 0.3.0)
PHP Version: 5.2.1 OS: Linux
Roadmaps: (Not assigned)    
Subscription  


 [2007-09-02 00:54 UTC] joepublick (Joe Publick)
Description: ------------ This bug is a 2-fold problem...there is a bug in the code, and also the following documentation on the PEAR website is wrong: http://pear.php.net/manual/en/package.text.text-captcha.php If you use the above documentation (as I did) it does not show how to properly setup the image CAPTCHA, so the following error occurs: "Error initializing Image_Text (font missing?!)" A previous bug report (#11957) identified this error message, but didn't explain why it's happening. Here is the reason it's happening: First, there are 2 relevant files: - image CAPTCHA's code is contained largely in Image.php - image CAPTCHA is dependent upon the Image_text package, whose code is contained in a file called Text.php CAPTCHA is setting the default image options (in Image.php) like this: var $_imageOptions = array( 'font_size' => 24, 'font_path' => './', 'font_file' => 'COUR.TTF', 'text_color' => '#000000', 'lines_color' => '#CACACA', 'background_color' => false); Notice the boolean value for 'background_color'...this is where the problem lies. This default value must be either a HEX value, or null, not a boolean. The init() function of the Image_text class, contained in Text.php, is not expecting a boolean in 'background_color', it is expecting a HEX value, or null. This bug only shows up when consumers of the image CAPTCHA do not specify an array of options that includes the 'background_color', because in that case image CAPTCHA passes the incorrect default value of "background_color' => false" to the Image_text class. The following code (as demonstrated in the example file that comes with the package) works because it DOES show how to set the $imageOptions array: require_once 'Text/CAPTCHA.php'; // Set CAPTCHA image options (font must exist!) $imageOptions = array( 'font_size' => 24, 'font_path' => './', 'font_file' => 'COUR.TTF', 'text_color' => '#DDFF99', 'lines_color' => '#CCEEDD', 'background_color' => '#555555' ); // Set CAPTCHA options $options = array( 'width' => 200, 'height' => 80, 'output' => 'png', 'imageOptions' => $imageOptions ); // Generate a new Text_CAPTCHA object, Image driver $c = Text_CAPTCHA::factory('Image'); $retval = $c->init($options); ...etc... The example code found at http://pear.php.net/manual/en/package.text.text-captcha.php does not show how to do this! The sample code that comes with the package, however, does indeed show you how to set the $imageOptions array. So there is a discrepancy of some sort in the documentation. To fix this bug, the CAPTCHA developer(s) need to change this code inside their Image.php file: var $_imageOptions = array( 'font_size' => 24, 'font_path' => './', 'font_file' => 'COUR.TTF', 'text_color' => '#000000', 'lines_color' => '#CACACA', 'background_color' => false); ...so that background_color is either null, or some HEX value, then the image CAPTCHA will work regardless of which documentation you refer to. PS: I am using a brand new install of PEAR (via go-pear.php), with a new install of the latest CAPTCHA package, everything installed August 31, 2007, so I assume it's the latest version of everything. Test script: --------------- Refer to this documentation to see the code fail: http://pear.php.net/manual/en/package.text.text-captcha.php And refer to the file called CAPTCHA_test.php in the documentation included with the package, for a working version. Expected result: ---------------- Image CAPTCHA should be generated Actual result: -------------- "Error initializing Image_Text (font missing?!)"

Comments

 [2007-09-02 09:13 UTC] wenz (Christian Wenz)
fixed in documentation; should be up and running once the docs rebuild.