captcha problems

I am having a bitch of a time with the captcha in the blog demo. Neither the "worked example" nor the copy that I built by hand works. I am running the app within the Zend Debugger from Eclipse.

The problem is that the URL http://myblog/index.php?r=post/captcha failse to produce a graphic. So I thought I would step through it with the debugger. The problem is on line 208 of CCaptchaAction.php It is

	$box=imagettfbbox(30,0,$this->fontFile,$code);

I have a Mac with 10.5.x and gd is definitely installed and so is FreeFont. GD-based Captchas work in other applications so it’s not GD. I understand that I can’t step into imagettfbbox because it is compiled code. However, I should be able to step OVER it, like the other library routines. When you step OVER them, debugger control returns to the next line of code. When I step over THIS one, it doesn’t come back, the application terminates exit value:0 and produces NO output.

Please help!

How about creating a little non-Yii script to test imagettfbbbox() method? You could use the .ttf file from the Yii distribution in /web/widgets/captcha/Duality.ttf:


$x = imagettfbbox(30,0,'/your/path/to/yii/web/widgets/captcha/Duality.ttf', 'teststring');

print_r($x);



If that doesn’t work either your GD lib probably has a problem. Maybe you find something here or by googling for Mac + PHP + GD.

Oh, and also use phpinfo() to check that your GD has freetype support:

Thanks both. I had already done both those things. My PHP Info states FreeType is enabled and I rebuilt it

already just to make sure. And My little

no yii test script similar to your suggestion fails to produce any output just like in the real world. Anyway this is clearly not a yii problem but the yii team might be alert to it if anyone else gets it. Sigh why does this crap always happen to me.

Here is other vsn info

GD version bundled (2.0.34 compatible)

Freetype version 2.3.5

Is possible the freetype vsn is incompatible with my GD. I will go build an older vsn and see if that helps.

The only other thing is perhaps there is a problem with the Duality.ttf file. I will try some other font before giving up entirely.

I found the problem described here:

http://discussions.apple.com/message.jspa?messageID=7872720

The proposed solution they have would not fix the problem in general, it would require that any Mac server you deploy on have a custom library built for it, and that’s a huge barrier. I think perhaps a better solution for me would be to ditch yii’s captcha and substitute Zend’s one, I guess it does not use the TTF font call because I know for a fact that one works. And maybe the authors need to program around imagettfbbox in their own class. Anyway, this should be brought to the author’s attention. Not so many Macs actually serve inetz facing but a lot of people develop on them, so this issue could potentially affect adoption in a negative way.

I have reports from two friends of mine, both working on Mac and they have no problem with Yiis CAPTCHA at all. One has installed the PHP version from MacPorts the other is using MAMP. Maybe you can give one of those a try?

Hi,

I got the same problem upgrading my virtual Ubuntu server to 9.10. When I open the captcha image that failed to be generated in a new tab I get this:


PHP Error


Description


imagettfbbox() [<a href='function.imagettfbbox'>function.imagettfbbox</a>]: Could not read font


Source File


/media/win_ws/yii-1.1a.r1436/framework/web/widgets/captcha/CCaptchaAction.php(208)


00196:         imagecolordeallocate($image,$backColor);

00197: 

00198:         $foreColor=imagecolorallocate($image,

00199:             (int)($this->foreColor%0x1000000/0x10000),

00200:             (int)($this->foreColor%0x10000/0x100),

00201:             $this->foreColor%0x100);

00202: 

00203:         if($this->fontFile===null)

00204:             $this->fontFile=dirname(__FILE__).'/Duality.ttf';

00205: 

00206:         $offset=2;

00207:         $length=strlen($code);

00208:         $box=imagettfbbox(30,0,$this->fontFile,$code);

00209:         $w=$box[4]-$box[0]-$offset*($length-1);

00210:         $h=$box[1]-$box[5];

00211:         $scale=min(($this->width-$this->padding*2)/$w,($this->height-$this->padding*2)/$h);

00212:         $x=10;

00213:         $y=round($this->height*27/40);

00214:         for($i=0;$i<$length;++$i)

00215:         {

00216:             $fontSize=(int)(rand(26,32)*$scale*0.<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />;

00217:             $angle=rand(-10,10);

00218:             $letter=$code[$i];

00219:             $box=imagettftext($image,$fontSize,$angle,$x,$y,$foreColor,$this->fontFile,$letter);

00220:             $x=$box[2]-$offset;

Stack Trace


#0 /media/win_ws/yii-1.1a.r1436/framework/web/widgets/captcha/CCaptchaAction.php(208): imagettfbbox()

#1 /media/win_ws/yii-1.1a.r1436/framework/web/widgets/captcha/CCaptchaAction.php(111): CCaptchaAction->renderImage()

#2 /media/win_ws/yii-1.1a.r1436/framework/web/CController.php(300): CCaptchaAction->run()

#3 /media/win_ws/yii-1.1a.r1436/framework/web/CController.php(278): SiteController->runAction()

#4 /media/win_ws/yii-1.1a.r1436/framework/web/CController.php(257): SiteController->runActionWithFilters()

#5 /media/win_ws/yii-1.1a.r1436/framework/web/CWebApplication.php(320): SiteController->run()

#6 /media/win_ws/yii-1.1a.r1436/framework/web/CWebApplication.php(120): CWebApplication->runController()

#7 /media/win_ws/yii-1.1a.r1436/framework/base/CApplication.php(135): CWebApplication->processRequest()

#8 /media/win_ws/nhbs_yii/trunk/index.php(11): CWebApplication->run()

All my Yii files reside on the c: drive on my Vista host. The virtual client machine mounts a windows share using cifs to access the files. This works just fine and my Linux server serves the shared Windows files without any problems.

For some reason it doesn’t work for fonts in the new version of Ubuntu. I had to move the font file(Duality.ttf) to a native Linux directory. I have been setting the exact same permissions on the font file and now it works.

Unfortunately this means that I have to change the path to the captcha font in the file CCaptchaAction.php. This is not a very nice way of solving the problem but it is OK in my test environment.

Does anybody else have this problem on Ubuntu 9.10?