在Zend Captcha的配置数组中有什么问题?

时间:2013-01-28 10:32:48

标签: php zend-framework captcha

我正在使用Zend_Form_Element_Captcha来创建Captcha图像,如下所示: -

$captcha = new Zend_Form_Element_Captcha(
                   'captcha',
                    array(
                        'label' => 'Please write the characters you see in the image:',
                        'captcha' => array(
                                         'captcha' => 'Image',
                                         'wordLen' => 6,
                                         'timeout' => 900,
                                          'font' => '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf',

                                     )
                        )
    );

$form = new Zend_Form();

$form->addElement($captcha);

这是创建Captcha Image但不是正确的方式。 信件根本不可读。 这就是我得到的......

enter image description here

enter image description here

我也试图改变字体,但结果却一样。有什么建议吗?

2 个答案:

答案 0 :(得分:1)

我在本地环境中尝试过您的代码。如果您使用的是Windows,请使用以下代码。 我使用了绝对的字体路径。

$captcha = new Zend_Form_Element_Captcha(
                        'captcha',
                        array(
                            'label' => 'Please write the characters you see in the image:',
                            'captcha' => array(
                                'captcha' => 'Image',
                                'wordLen' => 6,
                                'timeout' => 900,
                                'font' => 'C:/Windows/Fonts/Arial.ttf',
                                'imgDir' => APPLICATION_PATH . '/../public/captcha/',
                                'imgUrl' => '/captcha/'
                            )
                        )
        ); 

答案 1 :(得分:0)

试试这个

$captcha = new Zend_Form_Element_Captcha(
   'captcha',
    array(
        'label' => 'Please write the characters you see in the image:',
        'captcha' => array(
             'captcha' => 'Image',
             'wordLen' => 6,
             'timeout' => 900,
             'dotNoiseLevel' => 20,
             'lineNoiseLevel' => 3,
             'fontSize' => 25,
             'font' => '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf',

         )
        )
);