Zend验证码图片生成空白 [英] Zend captcha Image generates blank

查看:118
本文介绍了Zend验证码图片生成空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图像验证码随机显示空白验证码。 10次​​尝试中大约4次。

The image captcha randomly displays a blank captch. Roughly 4 out of 10 attempts.

我已经发现了问题,并且 zend论坛上的帖子建议,唯一的解决方法是编辑Zend Framework代码。

I have already discovered the problem and a post on the zend forum suggest the only fix is to edit the Zend Framework code.

是否可以在不编辑ZF代码的情况下解决此问题?
从那时起Zend为何还没有在发行版中解决此问题,我在更改日志中查找了内容,但与此无关?

Is there any way to fix this without editing the ZF code? How come Zend have not fixed this in the releases since then, I have a look in the change log but nothing related to this?

$w     = $this->getWidth();
$h     = $this->getHeight();
$fsize = $this->getFontSize();

$img_file   = $this->getImgDir() . $id . $this->getSuffix();
if(empty($this->_startImage)) {
    $img = imagecreatetruecolor($w, $h);
} else {
    $img = imagecreatefrompng($this->_startImage);
    if(!$img) {
        require_once 'Zend/Captcha/Exception.php';
        throw new Zend_Captcha_Exception("Can not load start image");
    }
    $w = imagesx($img);
    $h = imagesy($img);
}
$text_color = imagecolorallocate($img, 0, 0, 0);
$bg_color   = imagecolorallocate($img, 255, 255, 255);
imagefilledrectangle($img, 0, 0, $w-1, $h-1, $bg_color);
$textbox = imageftbbox($fsize, 0, $font, $word);
$x = ($w - ($textbox[2] - $textbox[0])) / 2;
$y = ($h - ($textbox[7] - $textbox[1])) / 2;

// Edit: check not over 100
if($x > 50){ $x = 50;}
if($y > 100){ $y = 100;}

imagefttext($img, $fsize, 0, $x, $y, $text_color, $font, $word);

使用die()进行调试证明是这种情况:

die("img=".$img ." fsize=".$fsize. " x=".$x ." y=".$y . " h=".$h );
img=Resource id #159 fsize=24 x=1073741923.5 y=41 h=50


推荐答案

根据提供的链接,它可能不是Zend Framework错误,而是带有imageftbbox的错误。我建议扩展Zend_Captcha_Image并复制 _generateImage 函数并将 $ x =设置为合理的值(我看到45论坛帖子)(太大)(可能> 100)。这样一来,您无需更改实际的Zend Framework代码即可进行建议的修复/修改。

According to the link provided, it may not be a Zend Framework bug, but something with imageftbbox. I would suggest extending Zend_Captcha_Image and copying the _generateImage function and setting $x = to something reasonable ( I saw 45 on the forum post ) when it is too big ( perhaps > 100 ). This allows you to put in the suggested fix / hack without changing the actual Zend Framework code.

这篇关于Zend验证码图片生成空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆