+ Reply to Thread
Results 1 to 6 of 6

Thread: JpGraph

  1. #1
    cmate is offline 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.

  2. #2
    Tekerson is offline 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

  3. #3
    cmate is offline 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.

  4. #4
    Eugen is offline Senior Member
    Join Date
    Sep 2008
    Location
    Croatia
    Posts
    400

    Default

    did you check header?
    it looks like header ("Content-type: image/png" ); has been overwriten somewhere..

  5. #5
    cmate is offline 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?

  6. #6
    cmate is offline 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.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts