the imagejpeg() function echoes the image string, but text echoed in
actions seem to get thrown out in symfony (I don't know the exact
mechanism for this, but it seems to be the case).  You need to call
$this->renderText(imagejpeg($image)) or something along those lines so
that the action actually sends the text output somewhere.  Right now
there is nothing being output to the response.  Thats why the function
works outside of symfony, but doesn't when you are working within
symfony.  So your final method should look something like this:

public function executeShowCaptcha(sfWebRequest $request)
{
              $this->getResponse()->setContentType('image/jpeg');
              return $this->renderText(myTools::genCaptcha(uniqid
()));
}

I haven't tried it, but I think it should work.

HTH
--Casey


On Oct 12, 5:45 am, Ahmed <ghaliano2...@gmail.com> wrote:
> @Alexandre
> no change
> I have Always a 0x0 blanc image
> i search in all my project for a line break
> and i don't found any off them
>
> @Vasos
> I try this trick
>
> Cordialy
> Ahmed
> On 12 oct, 13:41, basos g <noxe...@gmail.com> wrote:
>
>
>
> > 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