Saturday, 15 August 2009

Zend frame work dynamic image : imagecreate

A short example how to create an image in the zend MVC frame work.

It is the same code as you would do it in PHP. Below i explain how to place it in the framework.

I created a conrtoller, and in side an Action to get information from the database. In the view i put the code to create the Image.

I have
/application/CreatemyimageController.php



class CreatemyimageController extends Zend_Controller_Action
{

public function init()
{

/* Initialize action controller here */
}

public function indexAction()
{

}

public function indexpageimage(){
// i here get the date from the DB or any other info.
// send it to the view
$this -> view -> cell_list = $row;
}




In the view i create a file. indexpageimage.phtml

cell_list;


header("Content-type: image/png");
$im = @imagecreate(110, 20)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, $string, $text_color);
imagepng($im);
imagedestroy($im);


And my url is
http://localhost/createmyimage/indexpageimage/

This is it !

1 comments:

  1. Sorry, but this tutorial sucks.

    ReplyDelete