Pyrocms front end controller - can't output image to the browser

820 Views Asked by At

here is the code code below

class Home extends Public_Controller
{
    /**
     * Constructor method
     *`enter code here`
     * @author PyroCMS Dev Team
     * @access public
     * @return void
     */
    public function __construct()
    {
        parent::__construct();  
    }


public function testimg(){
    header("Content-type: image/png");
    $image = imagecreatetruecolor(200, 200);
    imagepng($image);     
}
}

but when i call this controller like (http://localhost/sitename/home/testimg). i got the error below

The image "http://localhost/sitename/home/testimg" cannot be displayed because it contains errors.

Kindly help me with this issue i am new to pyrocms.

2

There are 2 best solutions below

1
On

That's nothing to do with PyroCMS or even CodeIgniter, you've just set up the image wrong. That is a generic PHP error.

0
On

Problem Solved : there was always an extra space when echo something, i don't know why - ob_clean() does the job.

public function testimg(){
    ob_clean();
    header("Content-type: image/png");
    $image = imagecreatetruecolor(200, 200);
    imagepng($image);     
}