Zend Framework Forum

Go Back   Zend Framework Forum > Zend Framework General discussions > Resources for Developers

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-18-2009, 07:09 PM
Junior Member
 
Join Date: Jan 2009
Posts: 4
Default JpGraph

Hi.
How can I render a GD or JpGraph image in a Zend Framework view ?
I'd like to do something thike this:
public function indexAction()
{

$im = imagecreatetruecolor ( 300, 200);
$black = imagecolorallocate ($im, 0, 0, 0 );
$white = imagecolorallocate ($im, 255, 255, 255 );

imagefilledrectangle ($im,0, 0,399,99 ,$white);
imagerectangle ($im,20, 20,250,190 ,$black);

header ("Content-type: image/png" );
$this->view->imagen=$im;
}

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-18-2009, 09:27 PM
Senior Member
 
Join Date: Jul 2008
Posts: 288
Default

Yep, pretty close.

You can either add a view with
[php]
<?php echo $this->imagen; ?>
[/php]
in it to output the contents of the image, or disable view rendering with
[php]
$this->_helper->viewRenderer->setNoRender();
[/php]
and echo from the controller.

or moving everything you have there into the view (leaving the controller empty) would be another (possibly better?) option.
__________________
Brenton Alker
PHP Developer - Brisbane, Australia

blog.tekerson.com | twitter.com/tekerson | brenton.mp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-19-2009, 08:31 AM
Junior Member
 
Join Date: Jan 2009
Posts: 4
Default

Ok.
Then I try with this controller:

public function indexAction()
{

}

And In the script view:
<?
$im = imagecreatetruecolor ( 300, 200);
$black = imagecolorallocate ($im, 0, 0, 0 );
$white = imagecolorallocate ($im, 255, 255, 255 );

imagefilledrectangle ($im,0, 0,399,99 ,$white);
imagerectangle ($im,20, 20,250,190 ,$black);

header ("Content-type: image/png" );
imagepng ($im);
?>


But the browser outputs somethig like
�PNG  IHDR,�ݽK�IDATx���1� A1����+��q�'�+6P1������D1BL�!�D1BL�!�D 1BL�!�D1BL�!�D1B�sx����?U���Jpe�k�sb "��!&B��b"��!&B��b"��!&B��b"��!&B��b"��!& B��b"��!&B��b"��!&B��b"��!&B��b"��!&B��b" ��!&B��b"��!&B��b"��!&B��b"��!&B��b"��!&B ��b"��!&B��b"��!&B��b"��!&B��b"��!&B��b"� �!&B��b">��� ɬ?��IEND�B`�

If I run the view script separately (without Zend framewor) it's Ok.
Any suggestions?
Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-19-2009, 09:04 AM
Senior Member
 
Join Date: Sep 2008
Location: Croatia
Posts: 356
Send a message via MSN to Eugen
Default

did you check header?
it looks like header ("Content-type: image/png" ); has been overwriten somewhere..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-19-2009, 09:29 AM
Junior Member
 
Join Date: Jan 2009
Posts: 4
Default

Quote:
Originally Posted by Eugen View Post
did you check header?
it looks like header ("Content-type: image/png" ); has been overwriten somewhere..
Yes. I've found that the problem is the layout.
If I don't use layout it's ok.
I have In my bootstrap

$view = Zend_Layout::getMvcInstance()->getView();
$view->doctype('XHTML1_STRICT');


And the layot script is very simple
<html>
<head>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Zend Framework Application</title>
</head>
<body>
<?= $this->layout()->content ?>
</body>
</html>

I want to use my layout. What's wrong?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-19-2009, 10:14 AM
Junior Member
 
Join Date: Jan 2009
Posts: 4
Default

I must disable layout
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
I can render images correctly..
Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT. The time now is 12:16 PM.


Designed by: Miner Skinz Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0