2009/10/12 Ahmed <ghaliano2...@gmail.com>

>
> Hi all;
> I use symfony 1.2.9
> I have a strange error in ouputing image with symfony , so i have a
> simple function to create image
> public static function genCaptcha($pass){
>              $image = ImageCreatetruecolor(100, 20);
>              $clr_white = ImageColorAllocate($image, 255, 255, 255);
>              $clr_black = ImageColorAllocate($image, 0, 0, 0);
>              imagefill($image, 0, 0, $clr_black);
>
>              // *** Set the image height and width ***
>              imagefontheight(15);
>              imagefontwidth(15);
>
>              // *** Add the passcode in white to the image ***
>              imagestring($image, 5, 30, 3, $pass, $clr_white);
>
>              // *** Throw in some lines to trick those cheeky bots!
> ***
>              imageline($image, 5, 1, 50, 20, $clr_white);
>              imageline($image, 60, 1, 96, 20, $clr_white);
>              imageline($image, 5, 1, 100, 50, $clr_white);
>              // *** Output the newly created image in jpeg format ***
>              imagejpeg($image);
>
>              // *** Clear up some memory... ***
>              imagedestroy($image);
> }
>
> And in the action i write:
> public function executeShowCaptcha(sfWebRequest $request)
> {
>              $response = $this->getResponse();
>              $response->setContentType('image/jpeg');
>
>              myTools::genCaptcha(uniqid());
>
>              $this->setLayout(false);
>
>              return sfView::NONE;
> }
> i use it in a template like this <img src="<?php echo url_for('home/
> showCaptcha')?>" />
> But i dont see any image in my template and whene i try to point it
> directly on the url like :
> http://127.0.0.1/test/frontend_dev.php/home/showCaptcha
> also i dont see the generated image
>




For me it worked a code like this in the action:

        $response = $this->getResponse() ;
        $response->setContentType('the contet type header');
        $response->setContent($image->asString());
        $response->send() ;



But this supposes that you have the image as an object that supports the
asString() method, whick returns the data as string instead of outputing
them directly.

One php method that returns string data is file_get_contents('filepath') but
it reads from disk. Maybe you could find something that returns a memory
image as string. Try setContent($image) as a speculation. If you find the
solution say it here.

Vasos

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to