The captcha image won't display (it just shows a red cross).
In my view file I use the following:

<div id="captchaID" ><?php echo $this->Html->image($this->Html-
>url(array('controller'=>'users', 'action'=>'captcha'), true),
array('style'=>'','vspace'=>2)); ?>
</div>

.... in my controller I have the following function / action:
function captcha()  {
        $this->autoRender = false;
        //$this->layout = 'ajax';
        $this->Captcha = new CaptchaComponent(); //make instance
        $this->Captcha->startup($this); //and do some manual calling
        $this->Captcha->create();
}
        }
... and the create function in the component is as follows:

function create($width='120',$height='40',$characters='6') {
        $code = $this->generateCode($characters);
        /* font size will be 75% of the image height */
        $font_size = $height * 0.70;
        $image = @imagecreate($width, $height) or die('Cannot initialize new
GD image stream');
        /* set the colours */
        $background_color = imagecolorallocate($image, 220, 220, 220);
        $text_color = imagecolorallocate($image, 10, 30, 80);
        $noise_color = imagecolorallocate($image, 150, 180, 220);
        /* generate random dots in background */
        for( $i=0; $i<($width*$height)/3; $i++ ) {
                imagefilledellipse($image, mt_rand(0,$width), 
mt_rand(0,$height), 1,
1, $noise_color);
        }
        /* generate random lines in background */
        for( $i=0; $i<($width*$height)/150; $i++ ) {
                imageline($image, mt_rand(0,$width), mt_rand(0,$height),
mt_rand(0,$width), mt_rand(0,$height), $noise_color);
        }
        /* create textbox and add text */
        $textbox = imagettfbbox($font_size, 0, $this->font, $code) or
die('Error in imagettfbbox function');
        $x = ($width - $textbox[4])/2;
        $y = ($height - $textbox[5])/2;
        $y -= 5;
        imagettftext($image, $font_size, 0, $x, $y, $text_color, $this-
>font , $code) or die('Error in imagettftext function');
        /* output captcha image to browser */
        header('Content-Type: image/jpeg');
        imagejpeg($image);
        imagedestroy($image);

        $this->Controller->Session->write('security_code',$code);
}

(which I got from 
http://www.devarticles.in/cakephp/simple-captcha-component-for-cakephp-new/
)

Any ideas as to why the image is not displaying?  Is there a way that
I can debug this?

Thanks.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to