图像验证码随机显示空白捕获。大约有十分之四的尝试。
我已经发现了这个问题,a post on the zend forum suggest唯一的解决方法是编辑Zend Framework代码。
有没有办法在不编辑ZF代码的情况下解决这个问题? 为什么Zend从那时起没有在发行版中解决这个问题,我看看更改日志但是没有任何相关内容?
$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
答案 0 :(得分:0)
根据提供的链接,它可能不是Zend Framework错误,而是与imageftbbox有关。我建议扩展Zend_Captcha_Image并复制_generateImage
函数并将$x
=设置为合理的(我在论坛帖子中看到45),当它太大(可能> 100)时。这允许您在不更改实际Zend Framework代码的情况下输入建议的修复/ hack。
答案 1 :(得分:0)
你是不是偶然在Debian / Ubuntu上运行php 5.3.2? PHP(而不是Zend)中有imageftbbox bug导致它偶尔返回异常值。
我认为这与使用32位gcc编译某个GD版本有关。我用验证码图像看了很多次。简单的解决方法是将PHP升级到最新版本,或者我认为它已在下一版本的PHP中修复。